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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent: Problem with data from Previous month 2

Status
Not open for further replies.

SmileyFace

Programmer
Sep 10, 2002
99
0
0
US
I am trying to retrieve data for the previous month...since it is Jan right now, the formula Month(CurrentDate)-1 generates a '0' which gives an error: "A month number must be between 1 and 12". To bypass this the following code was written, but doesn't seem to work...please note what is highlighted...

if {?ReportPeriod} = "CurrentMonth" then
if {?ReportSite} = "X" then
"Created in " + ToText(CurrentDate, "MMMM yyyy")
else
"Created in " + ToText(CurrentDate, "MMMM yyyy") + " for " + {?ReportSite}
else
if {?ReportPeriod} = "PreviousMonth" then
if Month(CurrentDate) = 1 then (...here is where it should go in the loop)
if {?ReportSite} = "X" then
"Create in December " + ToText(Year(CurrentDate)-1)
else
"Created in December " + ToText(Year(CurrentDate)-1) + " for " + {?ReportSite}
else (...but it still seems to be coming into the 'else' section and giving that error)
if {?ReportSite} = "X" then
"Created in " + ToText(DateTime(Year(CurrentDate), Month(CurrentDate)-1, Day(CurrentDate)), "MMMM yyyy")
else
"Created in " + ToText(DateTime(Year(CurrentDate), Month(CurrentDate)-1, Day(CurrentDate)), "MMMM yyyy") + " for " + {?ReportSite}
else
if {?ReportSite} = "X" then
{?ReportPeriod}
else
{?ReportPeriod} + " for " + {?ReportSite}

I would really appreciate any help offered with this. Thanks in advance!!
 
Without rewriting your formula, just a comment. Try using the dateserial function:

dateserial(year(currentdate),month(currentdate)-1,day(currentdate))

The formula returns 12/17/2004 for currentdate = 1/17/05.

-LB
 
Thanks a lot lbass!! I substituted DateTime for DateSerial like you mentioned, and it worked like a charm! Any idea why DateTime was giving an error and also what is the difference between DateTime & DateSerial? As you can tell, I'm not very good with Crystal syntax! :) Well, thanks again for the help. I appreciate it!
 
Dateserial takes into account that values in the arguments for a date refer to numbers that are date-specific values with the corresponding limitations and are not simply numbers. Check out the help files for more information.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top