Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Dynamic Date Range Post Reply Post New Topic
Author Message
db3712
Groupie
Groupie
Avatar

Joined: 30 Oct 2008
Location: United States
Online Status: Offline
Posts: 44
Quote db3712 Replybullet Topic: Dynamic Date Range
     Posted: 30 Nov 2011 at 6:37am
If I wanted to schedule a report every Monday and pull records based on a date range from 5/1/2011 to the previous Friday the report is being run on, how would I do that?   For instance, if I were to schedule a report starting this upcoming Monday (Dec 5th), I would want the report to pull 5/1/2011 - 12/2/2011.  Every week that last date would increase by 7 days.   Thank you!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 30 Nov 2011 at 8:00am
{table.datefield} in date(2011,5,1) to dateadd('d',-3,date(2011,12,5))
IP IP Logged
db3712
Groupie
Groupie
Avatar

Joined: 30 Oct 2008
Location: United States
Online Status: Offline
Posts: 44
Quote db3712 Replybullet Posted: 30 Nov 2011 at 8:34am
Thank you for your quick response.  I still foresee a problem.  The 12\5\2011 date isn't constant.  The report will be run every Monday.  I need the the first date to remain constant which is 5\1\2011 which your formula provides for, but the end date will change.  On 12\5, the report will pull 5\1\2011 through 12\2\2011 which is the preceding Friday.    The following Monday (12\12\2011), the report will pull 5\1\2011 through 12\9\2011 which is 3 days prior to that report being run.  The end date will always be 3 days prior to the day each weeks report is ran.  Thanks again for your help.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 30 Nov 2011 at 12:08pm
sorry, i copied and pasted using that a sample.
it was supposed to be
{table.datefield} in date(2011,5,1) to dateadd('d',-3,currentdate)
 
as your currentdate is always a monday when you run the report.
 
IP IP Logged
db3712
Groupie
Groupie
Avatar

Joined: 30 Oct 2008
Location: United States
Online Status: Offline
Posts: 44
Quote db3712 Replybullet Posted: 01 Dec 2011 at 4:48am
Thank you!  Really appreciate it.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 01 Dec 2011 at 5:14am
in case you need a little more flexibility (like you can't always run the report on Mnnday or you occasionally run it ad hoc during the week) I think this would always give you the friday before the current day.
 
{table.datefield} in date(2011,5,1) to dateadd('d',-(weekday(currentdate,crsaturday)),currentdate)
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