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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start Date as Yesterday @ 06:00am

Status
Not open for further replies.

woolade

Technical User
Nov 8, 2001
51
AU
I am trying to set parameters so that if the user selects any day from the list i.e. "Tuesday" or "Wednesday" then the start date parameter will be the day before @ a certain time. For example if the user selects "Tuesday" then I want the start date to be the day before @ 06:00 (i.e. Monday 06:00am). What is the correct formula to specify a particular date and a specific time?

I thought something like
DateTime((Current Date-1),6,0,0) however this is not working!
 
There might be a more elegant way, but I used:

DateTime(
Year({?test}),
Month({?test}),
Day({?test}) - 1,6,0,0 )

The parameter should be a DATE type. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
Ken, Would this not fail if the {?test} was the 1st of the month? I think it will because Year({?test}) and Month({?test}) will not revert to the previous year or month if necessary.

To take this into account try:

DateTime(
Year({?test}-1),
Month({?test}-1),
Day({?test}-1) ,6,0,0 )

I can't think of a more elegant way either!

Steve Phillips, Crystal Consultant
 
Good catch! Shows the importance of testing.
Yes, mine would fail on the first of the month. Yours takes that into account nicely. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
I was able to get the desired results with this formula.
datetime({?date}-1, ctime (6,0,0))

Having access to CR 8 only, I don't know if works with others versions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top