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
 General SQL Server Forums
 New to SQL Server Programming
 get a date lesser than 2 month of getdate()???

Author  Topic 

meenus
Starting Member

10 Posts

Posted - 2012-01-17 : 08:59:35
In sql 2005,

How can i get a date lesser than 2 month of getdate()???

For eg: Getdate =01/09/2011

result should be =01/07/2011

another eg:

Get date=01/01/2012

result is =01/11/2011

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-17 : 09:06:45
Use DATEADD function
DECLARE @dt DATETIME; 

SET @dt = '20110901';
SELECT DATEADD(MONTH,-2,@dt);

SET @dt = '20120101';
SELECT DATEADD(MONTH,-2,@dt);
Go to Top of Page
   

- Advertisement -