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 2008 Forums
 Transact-SQL (2008)
 Get Previous Months Date

Author  Topic 

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2011-08-29 : 12:05:57
How can I get the previous months date out of the getDate() function in '2011-08-01 00:00:00.000' format?

I want '2011-08-01 00:00:00.000' to look like '2011-07-01 00:00:00.000'

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-29 : 12:25:19
SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE())-1,0)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-29 : 12:26:40
also see

http://visakhm.blogspot.com/2010/01/some-quick-tips-for-date-formating.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

qman
Constraint Violating Yak Guru

442 Posts

Posted - 2011-08-29 : 13:02:50
Great, thanks for both...!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-29 : 13:13:28
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -