471,887 Members | 1,499 Online

# last day of previous month

How can i calculate the last day of the previous month?

Jul 20 '05 #1
3 9618
"Killer" <ro*********@tiscali.it> wrote in message news:Sf*******************@twister2.libero.it...
How can i calculate the last day of the previous month?

The last date of previous month:

SELECT CURRENT_TIMESTAMP - DAY(CURRENT_TIMESTAMP)

If you need the date normalized (time of 12:00AM), then:

SELECT CAST(CONVERT(CHAR(8),
CURRENT_TIMESTAMP - DAY(CURRENT_TIMESTAMP),
112) AS DATETIME)

--
JAG
Jul 20 '05 #2
"Killer" <ro*********@tiscali.it> wrote in message news:<Sf*******************@twister2.libero.it>...
How can i calculate the last day of the previous month?

One way:

declare @dt datetime
set @dt = getdate()
select convert(char(8), dateadd(dd, -datepart(dd, @dt), @dt), 112)

Simon
Jul 20 '05 #3
Simple date arithmatic. Take first of current month (ie. 5/1/2004)
and subtract 1 day.
Jul 20 '05 #4

### This discussion thread is closed

Replies have been disabled for this discussion.