471,887 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

last day of previous month

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

Help me,please
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?

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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.