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)
 SELECT WHERE date 7 days in future

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2009-01-22 : 04:45:53
Hi,

I need to return all records where a datetime column is the date today + 7 days. Need to ignore the time part and just compare the dates.

Whats best way to do this?

Thank you

karthickbabu
Posting Yak Master

151 Posts

Posted - 2009-01-22 : 04:49:17

SELECT DATEADD(DAY,7,GETDATE())

====================================================
you realize you've made a mistake, take immediate steps to correct it.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-22 : 04:49:27
where dateadd(dd,datediff(dd,0,createdon),0) > dateadd(dd,datediff(dd,0,dateadd(dd,7,getdate())),0)
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-22 : 04:54:06
select * from urtable where dateadd(d,datediff(d,0,date),0)>=dateadd(d,datediff(d,0,getdate()),0) and dateadd(d,datediff(d,0,date),0)<=dateadd(d,datediff(d,0,getdate()+7),0)

Jai Krishna
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-22 : 08:51:40
if you want to use index on date column
select * from urtable where date>=dateadd(d,datediff(d,0,getdate())+7,0) and date<dateadd(d,datediff(d,0,getdate())+8,0)
Go to Top of Page
   

- Advertisement -