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

Clean method for Current week, Day = Monday

Status
Not open for further replies.

bmcauliffe2

Technical User
Aug 12, 2003
7
GB
This works for getting the Monday of the current week (system time).

Date (Year (CurrentDateTime),1,1)+7*({@weeknumber}-1)-DayOfWeek (Date (Year (CurrentDateTime),1,1))+2

With @weeknumber= int(DatePart("ww",CurrentDate))

Can anyone show me a muh cleaner way of getting the same result please ?

Thanks
 
Hi !

One way to get the monday date is to use the DateAdd function:

Dateadd("d",2,Maximum(LastFullWeek))

/Goran
 
I'll give that a go goranm.. thank you for your speedy reply.
 
Not much more elegant, but try:

DATEADD("ww", DATEDIFF("ww",cdate(1900,1,1),currentdate), cdate(1900,1,1))

-k
 
Much simpler goranm, I always forget to leverage CR functions and use old SQL methods - perhaps even:

maximum(lastfullweek)+2

-k
 
Reading this thread has been helpful, and I have a similar question. Is there a way (using DateAdd) to specify "yesterday" (like CurrentDate -1) and also a specific time range (like midnight to 8 am)? I've figured out the part about yesterday using a parameter, but cannot figure out how to do the same with time ranges.
Here's what I'm currently using to get "yesterday":

If RunInterval = "Yesterday" then
{DateTimeField} = currentdate -1
else
{DateTimeField} in {StartDateTime} to {EndDateTime}

Thanks in advance for any help!
 
(
If RunInterval = "Yesterday" then
{DateTimeField} = currentdate -1
else
{DateTimeField} in {StartDateTime} to {EndDateTime}
)
and
(
hour({DateTimeField}) < 9
)

This won't pass the SQL though, so I'd create a SQL Expression to create the hour and use it in the record selection formula.

-k
 
Thank you for the quick response--that makes perfect sense! I don't quite understand the last part though about &quot;won't pass the SQL&quot;. Can you elaborate on that?
 
If you select Database->Show SQL Query you'll see that the date part of the record selection formula is probably represented in the SQL, but time portion isn't. Hence the time filtering of the record selection will be done within Crystal, as opposed to the database.

Slower performance.

-k
 
Is there another way to do this so that the performance is not slow? I am running the report in Seagate Info and the report keeps failing (after two hours!!!) because it times out. Help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top