This code (done in Crystal 10) will select records based on a parameter (?date) for the last X number of dates (which can also be a parameter, or simply hardcoded like in the example). This code is useful when you only want one date entered as a parameter, as it could easily be accomplished with two date parameters. Enjoy!
//number of months to look back (CANNOT BE ZERO) must be 1-12
local numbervar months_back := 3;
local numbervar month_start:= iif(month({?date})<months_back, month({?date})+(13-months_back),month({?date})-(months_back-1));
local numbervar date_start:= 1;
local numbervar year_start:= iif(month({?date})<months_back, year({?date})-1,year({?date}));
//first day of month, X months ago
local datevar date_begin := DateValue (year_start, month_start, date_start);
//end date + X months - 1 day (to capture last day of month)
local datetimevar date_end := DateAdd("d",-1,DateAdd ("m",months_back,date_begin ));
//dates between start and end date
{Table.Date_Field} in (date_begin to date_end)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.