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
 Transact-SQL (2000)
 compare months

Author  Topic 

shekhar_dba
Starting Member

39 Posts

Posted - 2007-09-17 : 17:13:19
How to compare dates in last two months i.e. today is 9 month(sep) and i have required data which is available in both 8th(Aug) and 7th(july) month data.




SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-17 : 17:37:34
[code]SELECT *
FROM Table1
WHERE Col1 >= DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP), -61),
AND Col1 < DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP), 0)[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-18 : 01:57:26
or

SELECT *
FROM Table1
WHERE Col1 >= DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP)-2, 0)
AND Col1 < DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP), 0)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -