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)
 WHERE DATE IS Today()

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2007-11-01 : 09:18:34
I need to use a WHERE clause so that records are returned when I date field is today.

Is there a built in function to do this, e.g. I tried

WHERE expirydate = NOW()

But that didn't work.

The column is datetime and contains a date and a time, the time portion is irrelevent to me in this case.

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-11-01 : 09:23:27

Where Dateadd(day, Datediff(day, 0, expirydate), 0)= Dateadd(day, Datediff(day, 0, getdate()), 0)


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-11-01 : 10:09:38
I rpefer this because it will use an index on expirydate if one is available

Where expirydate >= Dateadd(day, Datediff(day, 0, getdate()), 0)
AND expirydate < Dateadd(day, Datediff(day, 0, getdate())+1, 0)

Kristen
Go to Top of Page
   

- Advertisement -