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

date conversion formula 1

Status
Not open for further replies.

swhitt

MIS
Aug 27, 2003
28
US
I am trying to get the date and year of the previous month to print out on a report that I've built. I am using the following formula:

if month(CurrentDate)=1 then
" "+MonthName(12) + " " + CStr(Year(CurrentDate)-1)
else
" "+MonthName(Month(CurrentDate)-1) +" " + CStr(Year(CurrentDate))

This works as I would like it to except that it prints out the year as a number. For instance, I would like to see:
July 2003 but it is printing July 2,003.00. What am I doing wrong? Any suggestions would be greatly appreciated.
 
Here - try this;

if month(CurrentDate)=1 then
" "+MonthName(12) + " " + ToText((Year(CurrentDate)-1),0,"")
else
" "+MonthName(Month(CurrentDate)-1) +" " + ToText((Year(CurrentDate)),0,"")


The 0 and "" tells Crystal to include 0 decimal places and no thousands separator when converting the numeric value to text. Enjoy!
 
Alternatively, you could use the following:

totext(DateAdd("m",-1,currentdate),"MMMM yyyy")

This will gove you the month and year for the previous month without having to check for January.

Reebo
Scotland (Sunny with a Smile)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top