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

DateAdd to find last day of last month

Status
Not open for further replies.

Wabush

Programmer
Jan 15, 2001
31
0
0
US
Hi there,

I am using the following formula to get the last day of the previous month and if the value of {?AsofDate} is April 30, 2002, then it returns March 30, 2002, instead of March 31, 2002.

Any reason this might happen?

Formula:
DateAdd("m", -1, {?Pm-?AsOfDate})
 
I think that's how dateadd is supposed to work...I have done the same sort of thing this way...

date(year{?As Of Date}),(month({?As Of Date}),1)-1

this takes your as of date (from your exampole) and in essence does this...
date(2002,04,1)-1=date(2002,3,31)
 
Okay, thanks, that makes sense.

But I still need to find the last day of the previous month - not the same day in the previous month..
Is there a way to find the number of days in a month so that I can write an if statement?
 
Try this, you can use current date or repolace it with a parameter date:

Date(Year(Currentdate),Month(Currentdate),1)-1 Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
That worked perfect !
Thanks a lot :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top