Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 First day of the three month back date

Author  Topic 

veparala
Starting Member

30 Posts

Posted - 2006-08-02 : 14:31:01
I need to write SQL code to get first day date of the three months back. ie when i run the SQL code today (ie Aug 02 2006), the code should display 05/01/2006 ( ie May 01 2006).

Can anybody help me on this?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-08-02 : 14:56:34
Try this:

select dateadd(month, datediff(month, 0, dateadd(month,-3,getdate())), 0)

Be One with the Optimizer
TG
Go to Top of Page

veparala
Starting Member

30 Posts

Posted - 2006-08-02 : 15:09:45
THANKS..IT WORKS FOR ME
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-02 : 15:33:16
Or this shorter one
SELECT	DATEADD(month, DATEDIFF(month, 0, GETDATE()) - 3, 0)



Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -