Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Formula 2

Status
Not open for further replies.

kempo1

MIS
Mar 31, 2003
2
US
I have the following formula causing problems,

IF MONTH(CurrentDate)= 1 THEN
DateTime ({@LastYear}-1,12,31,0 ,0 ,0 )
ELSE IF MONTH(CurrentDate)-1 IN [1,3,5,7,8,10,12] THEN
DateTime ({@CurrYear},MONTH(CurrentDate)-1,31,0 ,0 ,0 )
ELSE IF MONTH(CurrentDate)-1 IN [4,6,9,11] THEN
DateTime ({@CurrYear},MONTH(CurrentDate)-1,30,0 ,0 ,0 )
ELSE IF MONTH(CurrentDate)-1 IN [2] THEN
IF {@LeapYearForCurrYear} = 'Y' THEN
DateTime ({@CurrYear},2,29,0 ,0 ,0 )
ELSE
DateTime ({@CurrYear},2,28,0 ,0 ,0 )

When I run the report I get the following error:
A day number must be between 1 and the number of days in the month.

Can anyone spot a problem with this formula?
 
Please post your formulas for last year, current year and leap year testing. Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
dgilsdorf@trianglepartners.com
 
Leap Year Formula:
IF {@CurrYear} - (4*({@CurrYear}/4)) = 0 THEN "Y"
ELSE "N"

Current Year Formula:
YEAR(CurrentDate)

Last Year Formula:
{@CurrYear} - 1
 
It seems you are try to back 1 month. Try using DateAdd function :

DateAdd("m",-1,CurrentDate)

Should work fine. Reebo
Scotland (Going mad in the mist!)
 
Whoops....You want the last day of last month, try this :

DateAdd("d",-1,date(year(currentdate),month(currentdate),01))

Sorry, this should work.
Reebo
Scotland (Going mad in the mist!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top