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)
 Date Compare

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2008-08-24 : 14:49:49
Trying to do something very simple but it's returning no records.

Get today's date and add 4 hours then test against a field in the database...

SELECT * FROM my table WHERE myDateField > DATEADD(HOUR,4,GETDATE())

if myDateField is more than 4 hours old, return it.

Thanks,

Zath

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-08-24 : 15:57:03
if you want fields that are more than 4 hours old it would be

SELECT * FROM my table WHERE myDateField < DATEADD(HOUR,-4,GETDATE())


OR USE A DATEDIFF

SELECT * FROM my table WHERE DATEDIFF(MINUTE,myDateField,GETDATE()) > 240
Go to Top of Page
   

- Advertisement -