Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: How to filter by month and year, but not full date Post Reply Post New Topic
Author Message
flanman
Senior Member
Senior Member
Avatar

Joined: 04 Nov 2009
Online Status: Offline
Posts: 123
Quote flanman Replybullet Topic: How to filter by month and year, but not full date
     Posted: 14 Dec 2009 at 3:16pm
I have a table I have to retrieve data from for a report. The table has a field for month number(1-12) and year (2009).  I have to build a report to see the next 12 months of data from any given date.

The closest I came was

(field.year) >= Year(CurrentDate()) and (field.month) >= Month(CurrentDate());

When I run the report all I get is Dec. 2009 and Dec 2010 info, but nothing in between. I tried to add 11 to the month number, but it then goes past 12 which tells me I am doing something wrong.

* I do not have an actual date field in the table, just these two fields.

Thanks for any help.

Flanman
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 14 Dec 2009 at 7:15pm

Can't test this out at the moment but try something like:

date(table.year,table.month,1) in dateadd('d',-(day(currentdate)),currentdate) to dateadd('m',12,dateadd('d',-(day(currentdate)),currentdate))


Edited by DBlank - 14 Dec 2009 at 7:24pm
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 15 Dec 2009 at 6:47am

DBlank, very ingenious, but wouldn't you want to use day(currentdate)-1?

if today is the 15th, subtract 15 give you last day of last month. 
 
Just wondering
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 16 Dec 2009 at 6:53am
Yes I did miss tha extra day.
Thanks lockwelle.
date(table.year,table.month,1) in dateadd('d',-(day(currentdate))+1,currentdate) to dateadd('m',12,dateadd('d',-(day(currentdate))+1,currentdate))
IP IP Logged
flanman
Senior Member
Senior Member
Avatar

Joined: 04 Nov 2009
Online Status: Offline
Posts: 123
Quote flanman Replybullet Posted: 16 Dec 2009 at 11:31am
Thank you both. That worked like a charm. I am fairly new in a position and you all the great help I have received on this forum have really helped me out a lot.

Thanks again,

Flanman
IP IP Logged
ShadowData
Newbie
Newbie


Joined: 08 Mar 2011
Online Status: Offline
Posts: 1
Quote ShadowData Replybullet Posted: 08 Mar 2011 at 7:38am
Hello,

Just joined the forum. This is close to the solution I need but I need a little more help.

The table I am working from has month and year in separate fields. I need to filter the data to six or more orders in each of the last three months; currently it is returning records of 6 or more orders in any of the last three months.

Any help would be appreciated.

Thanks!
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