Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Date Selection in Crystal 2008 Post Reply Post New Topic
Author Message
brockloch
Groupie
Groupie


Joined: 03 Oct 2010
Location: United Kingdom
Online Status: Offline
Posts: 76
Quote brockloch Replybullet Topic: Date Selection in Crystal 2008
     Posted: 04 Jan 2012 at 6:00am
Hello
 
I could do with some help please.
 
I need to create a report that returns all orders recieved in the last 3 months, not including the current month.
 
I want the report to run without having to put a date range in when running the report.
 
I can split out the month number but once I have more than 12 months data in I will then start including data which is 12 months old?
 
Any help would be appreciated.
 
Thanks
 
Ed
brockloch
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 04 Jan 2012 at 6:45am
this might work

table.datefield in date((year(currentdate)-4), month(currentdate),day(currentdate)) to date((year(currentdate)-1), month(currentdate),day(currentdate))

put it into select expert


Edited by kostya1122 - 04 Jan 2012 at 6:47am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 04 Jan 2012 at 7:31am
i would tweak that a bit...maybe...
 
{table.datefield} in dateserial(year(currentdate),month(currentdate)-3,1) to dateserial(year(currentdate), month(currentdate),1-1)
IP IP Logged
brockloch
Groupie
Groupie


Joined: 03 Oct 2010
Location: United Kingdom
Online Status: Offline
Posts: 76
Quote brockloch Replybullet Posted: 04 Jan 2012 at 11:58am
Thank you that worked, however I don't really understand it!

In the meantime I found the datediff function and did this

datediff("M",CurrentDate,{SALES_ORDER.ORDER_DATE}),which returned 1,0,-1,-2,-3,-4 etc.

So I used the select expert between -3 and -1

Your way looks more efficient but is there any reason why mine wouldn't work - as I understand it?

Thanks for all your quick responses
brockloch
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 05 Jan 2012 at 4:42am
I think your idea would work fine.
Nothing in the logic is appearing to fail for your business rule.
 
Dateserial lets you convert a date by year, month and day.
When adding or subtracting values from each section it will move the entire item intot he next month or year.
It expects the format of (year + or - x, month + or - x, day + or - x)
dateserial(year(currentdate),month(currentdate)-3,1)
the current year, current month -3 months and the 1st day of the month.
 
 
dateserial(year(currentdate),month(currentdate),1-1)
the current year, current month  and the 1st day of the month -1 day which is the last day of the previous month regardless of the number of days in that month.
 


Edited by DBlank - 05 Jan 2012 at 4:44am
IP IP Logged
brockloch
Groupie
Groupie


Joined: 03 Oct 2010
Location: United Kingdom
Online Status: Offline
Posts: 76
Quote brockloch Replybullet Posted: 05 Jan 2012 at 12:34pm
Thanks that now makes sense.
brockloch
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