Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: First of next month Post Reply Post New Topic
Author Message
raccam1976
Newbie
Newbie


Joined: 04 Feb 2008
Location: United States
Online Status: Offline
Posts: 2
Quote raccam1976 Replybullet Topic: First of next month
    Posted: 04 Feb 2008 at 7:16am
I need to pull all records that fit the criteria of a specific date being the first of the next month...

DatePurchased = First of Next month.

Any ideas on how to get this to work?

Thank you

IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet Posted: 04 Feb 2008 at 2:34pm
There are a couple of ways to do this.  What database are you using?  If your database allows it, you could replace your tables with a command and use the current date to determine the first of the next month in SQL in the Where clause.  This will be the most efficient way to do this.
 
Another way to do this uses a formula called {@NextDate} that looks something like this:
Numbervar yy;
Numbervar mm;
yy := year(CurrentDate);
mm := month(CurrentDate);
if mm = 12 then mm := 1 else mm := mm + 1;
if mm = 12 then yy = yy + 1;
Date(yy, mm, 1)
You then add the following to the selection formula:  {table.DatePurchased} = {@NextDate}
 
The problem with this method is that it will probably bring all of the records to the workstation and then do its filtering.  If you're using Access or another file-based database, this is not an issue, but if you're using a client-server database (MS SQL, Oracle, etc.) then it's MUCH more efficient to use the Command.
 
-Dell
 
IP IP Logged
rvink
Groupie
Groupie
Avatar

Joined: 04 Feb 2008
Location: New Zealand
Online Status: Offline
Posts: 55
Quote rvink Replybullet Posted: 04 Feb 2008 at 7:40pm
{Table.DatePurchased} = DateAdd("m", 1, CDate(Year(CurrentDate), Month(CurrentDate), 1))

In other words, find the first of the current month, then add one month.


Edited by rvink - 04 Feb 2008 at 7:42pm
IP IP Logged
raccam1976
Newbie
Newbie


Joined: 04 Feb 2008
Location: United States
Online Status: Offline
Posts: 2
Quote raccam1976 Replybullet Posted: 05 Feb 2008 at 8:39am
Thank you, worked great !!! i am sooo happy...
Wink Tongue Smile Big%20smileStar
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.018 seconds.