469,343 Members | 5,377 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

last day of previous month

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

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

Help me,please


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?

Help me,please


One way:

declare @dt datetime
set @dt = getdate()
select dateadd(dd, -datepart(dd, @dt), @dt)
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.

Similar topics

5 posts views Thread by Ray via SQLMonster.com | last post: by
10 posts views Thread by ashore | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.