Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Select all records with a date of the next sunday Post Reply Post New Topic
Author Message
miamitourism
Newbie
Newbie
Avatar

Joined: 14 Jan 2011
Online Status: Offline
Posts: 24
Quote miamitourism Replybullet Topic: Select all records with a date of the next sunday
     Posted: 30 Oct 2012 at 10:26am
I am stumped and hoping someone here can help...
Dead
I have a report that will need to be run once per week, but not always on the same day. The report needs to include all the records from our DB that have dates from that following Sunday through Saturday. I would like this report to figure this out automatically based on the current date, so the user doesn't need to enter the range of dates into a parameter. My date field is a DateTime.
 
Examples:
Today is Tuesday, October 30th. If I ran the report today, I'd need to include records for November 4-10.
 
If I ran the report tomorrow, October 31st, I'd also need to include records for November 4-10.
 
Any ideas?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 30 Oct 2012 at 11:16am
maybe...
 
table.datefield in
dateadd('d',8-datepart('w',currentdate),currentdate)
to
dateadd('d',14-datepart('w',currentdate),currentdate)
 
IP IP Logged
miamitourism
Newbie
Newbie
Avatar

Joined: 14 Jan 2011
Online Status: Offline
Posts: 24
Quote miamitourism Replybullet Posted: 31 Oct 2012 at 3:44am
I think it worked :) :) :) Thank you so much!!! I would love to understand the reasoning in the formula. Could you word it out for me?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 31 Oct 2012 at 7:00am
dateadd('d',8-datepart('w',currentdate),currentdate)
 
this part takes todays date and figures out the weekday value of it (1=sunday, 2=monday, etc.). This is here to make it dynamic based on the day the report is run
this is just the static value of 8
this part adds a dynamic number of days (8-weekdayvalue) to today
the "8-weekdayvalue of today" always gets to you next sunday
 
Does that help?
 
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum