Jump to content
  • 0

Set Search Date Criteria Begin and End dates as weekly blocks (current week), by default


Question

I don't know if this is possible but I need to set Search date criteria Begin and End dates as weekly blocks (current week), by default. Meaning, the 'Begin Date' of the criteria has a default of the Sunday before (or on) the current date and the 'End Date' has a default of the Saturday after (or on) the current date. 

I'm using a Pivot Table to show totals over a workweek period, using a 'ServiceDate' date field for the columns. The user needs to see just the current week (7 days) so I have 'ServiceDate' in the Search or Filter section, with criteria for 'Begin Date' and 'End Date.' The user could type in the previous Sunday's date (the Begin Date) and the following Saturday's date (the End Date) to filter the results by that week. However, I need this to happen automatically when the datapage is loaded. 

I imagine you could populate the 'Begin Date' and 'End Date' criteria by either External Parameters or Default Values but I can't figure out how to calculate the Sunday-through-Saturday dates based on the current date. Any help would be really appreciated-- 

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
23 hours ago, DesiLogi said:

I don't know if this is possible but I need to set Search date criteria Begin and End dates as weekly blocks (current week), by default. Meaning, the 'Begin Date' of the criteria has a default of the Sunday before (or on) the current date and the 'End Date' has a default of the Saturday after (or on) the current date. 

I'm using a Pivot Table to show totals over a workweek period, using a 'ServiceDate' date field for the columns. The user needs to see just the current week (7 days) so I have 'ServiceDate' in the Search or Filter section, with criteria for 'Begin Date' and 'End Date.' The user could type in the previous Sunday's date (the Begin Date) and the following Saturday's date (the End Date) to filter the results by that week. However, I need this to happen automatically when the datapage is loaded. 

I imagine you could populate the 'Begin Date' and 'End Date' criteria by either External Parameters or Default Values but I can't figure out how to calculate the Sunday-through-Saturday dates based on the current date. Any help would be really appreciated-- 

Hi, have you tried using the current week as the comparison type? image.png.031073625db70de8aae7ab422773138f.png

Link to post
Share on other sites
  • 0

Hi SinJunYoung, 

Many thanks for that tip- I did not catch that as an option for the Search/Filter date.  It works really nicely except for one thing-I need the user to be able to change the week they want to Search/Filter by so the date needs a Begin/End criteria that's visible. I just need the current date to open by default so they don't have to enter it in themselves (bad design if they did). 

Here's some js I put together to get the Sunday before the current date and then add 6 days to it for the following Saturday, and then to put that into the Date Criteria for Begin and End dates. This allows the user to change the Search/Filter to different dates.  

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {

var curr = new Date();
day = curr.getDay();
firstday = new Date(curr.getTime() - 60*60*24* day*1000); 
//will return firstday (ie sunday) of the week
lastday = new Date(curr.getTime() + 60 * 60 *6 * 24 * 1000); 
//adding (60*60*6*24*1000) means adding six days to the firstday which results in lastday (saturday) of the week

var v_weekstart = firstday.toLocaleDateString('en-US'); 
var v_weekend = lastday.toLocaleDateString('en-US'); 
//removes the time from the day/time value so it can be used in the date criteria search

var v_weekend2 = (firstday.getMonth()+1) +"/"+ (firstday.getDate()+6) +"/"+ (firstday.getFullYear())
//this was added because in testing the variable 'lastday' wasn't always correct

document.forms[0].Value2_1.value = v_weekstart;
document.forms[0].Value2_2.value = v_weekend2;
//this puts the two date values in the two criteria so they can be used to search/filter

});
</script>

***I haven't thoroughly tested this yet so if anyone needs this check it out in detail before deploying. The code for the variable 'lastday' did not give me an accurate date last week, but this week it does, so it seems unreliable.  Therefore I used another method to add 6 days to come up with the end date of the current week  (variable v_weekend2). I left the original code for lastday in there in case someone needs it. 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...