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.
Author |
Topic |
jylland
Starting Member
27 Posts |
Posted - 2014-06-25 : 08:23:44
|
hi I have a select statement which should do this here below:WHERE TimeStamp = Last 24 hours'how can I program it ? I have tried -1, getdate() and more with no succes |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-06-25 : 08:32:53
|
quote: Originally posted by jylland hi I have a select statement which should do this here below:WHERE TimeStamp = Last 24 hours'how can I program it ? I have tried -1, getdate() and more with no succes
WHERE [timestamp] > DATEADD(dd,-1,GETDATE()); and if your data has rows with timestamps in the future as well, AND [timestamp] <= GETDATE() |
|
|
jylland
Starting Member
27 Posts |
Posted - 2014-06-25 : 08:38:21
|
what about this here ?(TimeStamp >= GETDATE() - 1) AND (TimeStamp <= GETDATE()) |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-06-27 : 09:19:15
|
It depends on which version of SQL Server you are using."Normal" date arithmetic are revoked on SQL Server 2012 and later.See http://www.sqltopia.com/?page_id=35 Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|