I frequently find I need to create reports that show if a date field falls on a specific day, for example if an event occurred yesterday. Here’s how:
-
Create a new variable called YesterdayMin and enter the formula:
CDateTime (CurrentDate-1,CTime(0,0,0) )
This variable takes the current day (today), and subtracts 1 to get yesterday. It then sets the time to 0:00:00 which is the start of the day (or midnight of the previous night.)
- Create a new variable called YesterdayMax and enter the formula:
CDateTime (CurrentDate-1,CTime(23,59,59) )
This variable takes the current day (today) and subtracts 1 to get yesterday. It then sets the time to 23:59:59 which is just before midnight at the end of the day.
- Now, you need to create a formula to evaluate your date field (Event_Date in our example):
If {Event_Date} in {@YesterdayMin} to {@YesterdayMax} then "yesterday" else "not yesterday"
You can then use the results of this formula to group or select your records.
Accounting for the Weekend
The above works well if your report runs every day. However, what if the report doesn’t run on the weekend, and you need to include Saturday and Sunday events in your Monday report? You just need to modify your YesterdayMin variable to include multiple days if it’s Monday. You can do this using the DayOfWeek function which evaluates the current day of the week (1 is Sunday, 2 is Monday, and so on.)
Change YesterdayMin to have the following formula:
If DayOfWeek (CurrentDate)=2 then CDateTime (CurrentDate-3,CTime(0,0,0) ) Else CDateTime (CurrentDate-1,CTime(0,0,0) )