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

Retrieving previous month end date

Status
Not open for further replies.

llafretaw

MIS
Oct 2, 2001
64
GB
Hi,
I'm trying to set the date of a particular parameter to a value that is roughly the month end of the previous month
I've tried doing syntax such as:
select @m.date = datepart(mm - 1, getdate())
If @m.date <> 2
BEGIN
select @r.date = '30' + @m.date + datepart(yyyy,getdate())
END
ELSE
BEGIN
select @r.date = '28' + @m.date + datepart(yyyy,getdate())
END

Any help would be welcomed


 
Try this:

select DateAdd(day, -1, convert(datetime, '1-' + datename(month, getdate()) + '-' + datename(year, getdate())))

...so we make a string that's the first day of the current month, convert it to a datetime and subtract a day.

HTH,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top