Print Page | Close Window

First of next month

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=2215
Printed Date: 03 May 2024 at 1:32pm


Topic: First of next month
Posted By: raccam1976
Subject: First of next month
Date 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




Replies:
Posted By: hilfy
Date 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 mailto:%7b@NextDate - {@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} = mailto:%7b@NextDate - {@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
 


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: rvink
Date 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.


Posted By: raccam1976
Date Posted: 05 Feb 2008 at 8:39am
Thank you, worked great !!! i am sooo happy...
Wink Tongue Smile Big%20smileStar



Print Page | Close Window