Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Parameter Default Value

Status
Not open for further replies.

Rachel30

Programmer
Mar 1, 2005
95
GB
Hi,

I would like to know how I can make a default value Date parameter.

Everytime the user refreshes the report I would like the user to be able see the date from and date to parameter automatically populated with yestersdays date. Any idea's I would be greatfull. Thanks Rachel.
 
Although I don't base the calculation of my default date on the current date, the following formula does compute a default date base on the default value of the parameter.

BeforeReadingRecords;
dateTimeVar AdjustedDate := datetime(2000,01,01);

//if the start date = Jan 1, 2000 then default date to 1st day of month 1 year ago else use date provided

if {?StartDate} < datetime(2000,02,01) then AdjustedDate := dateadd("m", -12,dateadd("d", -(day(currentdate) -1), currentdate)) else AdjustedDate := {?StartDate};

datetime(date(AdjustedDate), timevalue(00,00,00))
 
You could set the date parm to be a string and then the values eg 'Yesterday', 'Last week' etc. Then in your record selection formula you could have:
Code:
if {?DateParm}='Yesterday' then {mytable.myfield}>=currentdate-1
else if {?DateParm}='Last week' then {mytable.myfield} in lastfull week.....

ShortyA
 
Shortya,

Thanks for your idea however I would like to run date ranges like 22nd March 05 to 23rd March 05. I will never know what days the users would like to run the report. Normalyy they run them for yesterday but there may be instances when they would like to run for a week or month or just a ceratin day. Cheers Rachel
 
With the date parm being a string user-defined date ranges such as 22/03/2005 to 23/03/2005 could still be input. In your record selection formula add in :
Code:
(if {?Start} ='Yesterday' then {mytable.myfield} >=currentdate-1 else {mytable.myfield} in cdate({?Start}) to cdate({?End})
This would allow you to default your parameter to "Yesterday" but also allow user-specified date-ranges.

ShortyA
 
Both of these examples are the same in their basic concept and either should work for you. ShortyA obviously passes the parm value as a String while I pass it as a DateTime. I did this because the report was alreay written and in production before the desire to have a default date was requested.

Other than that mine is a bit more complex due to the fact that I am altering a parameter being passed to a stored procedure. Hence the "BeforeReadingReRcords" which allows me to alter the date range (set it to default value) prior to passing it to the stored procedure. I also choose to set the date to the first of the month in the same expression rather than in two simpler steps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top