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
 Help on Date function

Author  Topic 

aswadhama
Starting Member

3 Posts

Posted - 2011-07-26 : 16:16:18
I want to pull the records whose 'Open date' is less than one year comaring to today's system date. Can anybody help on how to do that??

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-07-26 : 16:22:57
Where OpenDate >= dateadd(yy,-1,Dateadd(dy,datediff(dy,0,GetDate()),0))

Corey

I Has Returned!!
Go to Top of Page

aswadhama
Starting Member

3 Posts

Posted - 2011-07-26 : 16:30:35
seventhnight,
Thanks so much. Let me try that and will update here about the status of the result.
Go to Top of Page

aswadhama
Starting Member

3 Posts

Posted - 2011-07-26 : 16:40:41
Did not work. The Error message is-

"YY" is not valid in the context
where it is used
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-07-26 : 17:55:19
Is this MS SQL Server? Because it works for me...

Select dateadd(yy,-1,Dateadd(dy,datediff(dy,0,GetDate()),0))
-------------------------
2010-07-26 00:00:00.000

Corey

I Has Returned!!
Go to Top of Page
   

- Advertisement -