I sometimes do this to provide users with a friendly prompt:
I create 3 parameters, a select from a list of predefined ranges as text, or enter a custom set of dates:
I use Start and End date formulas to do this, and reference them in the Record selection formula. This example has multiple periods, inclusive of using a picklist to select the range of interest for canned ranges, and allowing for a custom date range which is entered in another parameter:
////////////////////////////////////////////////////////////////////////////////////
// Starting date of the date range to be used against the column: {LOCALTIME}
// Constructed specifically in this manner to allow for pass through SQL
// Version 2
// Kai Molvig - 5/2/2002
////////////////////////////////////////////////////////////////////////////////////
// If Yesterday
If {?Predefined Date Range} = "Yesterday" Then
DateTime(Year(CurrentDate-1),Month(CurrentDate-1),Day(CurrentDate-1),0,0,0)
// If Last Week
Else
If {?Predefined Date Range} = "Last Week" Then
DateTime(Year(CurrentDate),Month(CurrentDate),Day(CurrentDate),0,0,0)-DayOfWeek(CurrentDate)-6
// If Last Month
Else
If {?Predefined Date Range} = "Last Month" Then
If Month (CurrentDate) = 1 Then
DateTime((Year(CurrentDate)-1),12,1,0,0,0)
Else
DateTime(Year(CurrentDate),Month(CurrentDate)-1,1,0,0,0)
// If Last Quarter
Else
If {?Predefined Date Range} = "Last Quarter" Then
If (Month(CurrentDate) < 4) Then
DateTime(Year(CurrentDate)-1,10,1,0,0,0)
Else
DateTime(Year(CurrentDate),3*Truncate((Month(CurrentDate)+2)/3)-5,1,0,0,0)
// If Last Year
Else
If {?Predefined Date Range} = "Last Year" Then
DateTime(Year(CurrentDate)-1,1,1,0,0,0)
// If Current Week
Else
If {?Predefined Date Range} = "Current Week" Then
DateTime(Year(CurrentDate),Month(CurrentDate),Day(CurrentDate),0,0,0)-DayOfWeek(CurrentDate)+1
// If Current Month
Else
If {?Predefined Date Range} = "Current Month" Then
DateTime(Year(CurrentDate),Month(CurrentDate),1,0,0,0)
// If Current Quarter
Else
If {?Predefined Date Range} = "Current Quarter" Then
DateTime(Year(CurrentDate),3*Truncate((Month(CurrentDate)-1)/3)+1,1,0,0,0)
// If Current Year
Else
If {?Predefined Date Range} = "Current Year" Then
DateTime(Year(CurrentDate),1,1,0,0,0)
// If Today
Else
If {?Predefined Date Range} = "Today" Then
DateTime(Year(CurrentDate),Month(CurrentDate),Day(CurrentDate),0,0,0)
// If Custom Time Period
Else
If {?Predefined Date Range} = "Custom Date Range" Then
Minimum({?Custom Date Range})
// This code should never be invoked
Else
CurrentDate+1
////////////////////////////////////////////////////////////////////////////////////
// Ending date of the date range to be used against the column: {LOCALTIME}
// Constructed specifically in this manner to allow for pass through SQL
// Version 2
// Kai Molvig - 5/2/2002
////////////////////////////////////////////////////////////////////////////////////
// If Yesterday
If {?Predefined Date Range} = "Yesterday" Then
DateTime(Year(CurrentDate-1),Month(CurrentDate-1),Day(CurrentDate-1),23,59,59)
// If Last Week
Else
If {?Predefined Date Range} = "Last Week" Then
DateTime(Year(CurrentDate),Month(CurrentDate),Day(CurrentDate),23,59,59)-DayOfWeek(CurrentDate)
// If Last Month
Else
If {?Predefined Date Range} = "Last Month" Then
If Month (CurrentDate) = 1 Then
DateTime(Year(CurrentDate)-1,12,1,23,59,59)
Else
DateTime(Year(CurrentDate),Month(CurrentDate),1,23,59,59)-1
// If Last Quarter
Else
If {?Predefined Date Range} = "Last Quarter" Then
If Month (CurrentDate) < 4 Then
DateTime(Year(CurrentDate)-1,12,1,23,59,59)
Else
DateTime(Year(CurrentDate),3*Truncate((Month(CurrentDate)-1)/3)+1,1,23,59,59)-1
// If Last Year
Else
If {?Predefined Date Range} = "Last Year" Then
DateTime(Year(CurrentDate)-1,12,31,23,59,59)
// If Current Week
Else
If {?Predefined Date Range} = "Current Week" Then
DateTime(Year(CurrentDate),Month(CurrentDate),Day(CurrentDate),23,59,59)-DayOfWeek(CurrentDate)+7
// If Current Month
Else
If {?Predefined Date Range} = "Current Month" Then
If Month (CurrentDate) = 12 then
DateTime(Year(CurrentDate),12,31,23,59,59)
Else
DateTime(Year(CurrentDate),Month(CurrentDate)+1,1,23,59,59)-1
// If Current Quarter
Else
If {?Predefined Date Range} = "Current Quarter" Then
If Month (CurrentDate) > 9 Then
DateTime(Year(CurrentDate),12,31,23,59,59)
Else
DateTime(Year(CurrentDate),3*Truncate((Month(CurrentDate)+2)/3)+1,1,23,59,59)-1
// If Current Year
Else
If {?Predefined Date Range} = "Current Year" Then
DateTime(Year(CurrentDate),12,31,23,59,59)
// If Today
Else
If {?Predefined Date Range} = "Today" Then
DateTime(Year(CurrentDate),Month(CurrentDate),Day(CurrentDate),23,59,59)
// If Custom Date Range
Else
If {?Predefined Date Range} = "Custom Date Range" Then
dateadd('s',-1,(Maximum({?Custom Date Range})+1))
// This code should never be invoked
Else
CurrentDate-1
// Record Selection Formula:
(
({SOL_VW_RPT_CLASS_SUM_DUR.LOCALTIME} >= {@Date Range Start})
and
({SOL_VW_RPT_CLASS_SUM_DUR.LOCALTIME} <= {@Date Range End})
)
and
<whatever else you have>
I think that this version had the bugs ironed out.
-k