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 2005 Forums
 Transact-SQL (2005)
 getdate() to select dates less than 15 months

Author  Topic 

want_to_know
Starting Member

13 Posts

Posted - 2008-04-07 : 16:43:20
Hi,
I need help. I want to select dates less than 15 months, as i am new to sql server , can anyone advise me.

I tried this query but it gave me the dates that are greater than 15 months

Selec calendardate from table
where calendardate < getdate()-457

Thanks

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-07 : 16:46:36
Select calendardate from table
where datediff(month,Yourdatecolumn,Getdate())<15
Go to Top of Page

want_to_know
Starting Member

13 Posts

Posted - 2008-04-07 : 16:50:45
Thank yo sodeep

It worked
God bless you


quote:
Originally posted by sodeep

Select calendardate from table
where datediff(month,Yourdatecolumn,Getdate())<15


Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-04-07 : 17:25:05
quote:
Originally posted by sodeep

Select calendardate from table
where datediff(month,Yourdatecolumn,Getdate())<15




This is a better way to do these types of queries, because it does not require SQL Server to run every row through a function, and it allows it to use indexes on the datatime column.

Select calendardate from table 
where
Yourdatecolumn >= dateadd(month,datediff(month,0,getdate())-15,0)


CODO ERGO SUM
Go to Top of Page
   

- Advertisement -