x

Dateadd function & CURRENT_TIMESTAMP

How do I return the date of 10/01/2009(first day of previous month) when using DATEADD function and CURRENT_TIMESTAMP.

more ▼

asked Nov 04, 2009 at 06:45 PM in Default

Dave 7 gravatar image

Dave 7
11 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first
SELECT [Now] = CURRENT_TIMESTAMP,
[1st of this month] = DATEADD(Month, DATEDIFF(Month, 0, CURRENT_TIMESTAMP), 0),
[1st of last month] = DATEADD(Month, DATEDIFF(Month, 0, CURRENT_TIMESTAMP)-1, 0)
more ▼

answered Nov 05, 2009 at 12:27 AM

Kristen gravatar image

Kristen ♦
2.2k 6 7 10

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1838
x94

asked: Nov 04, 2009 at 06:45 PM

Seen: 1648 times

Last Updated: Nov 05, 2009 at 12:28 AM