开发者

Get records 10 min before system datetime in SQL

i need to find the records 10 min before system cu开发者_JAVA技巧rrent datetime.

select Id,TimeStamp from ISAlive where RecordUpdatedDate < GETDATE() --SYSDATETIME()


select Id, TimeStamp
from ISAlive
WHERE RecordUpdatedDate = dateadd(minute,-10,getdate())

might be a starting point. Of course, it probably won't match exactly...

...if you want to get the most recent record that fits that criteria, however, try

SELECT TOP 1 ID, TimeStamp
FROM ISAlive
WHERE RecordUpdatedDate <= dateadd(minute, -10, getdate())
ORDER BY RecordUpdatedDate DESC


SELECT Id, TimeStamp
FROM ISAlive 
WHERE RecordUpdatedDate < DATEADD(minute,-10, SYSDATETIME());


You can do this with now()

SELECT Id, TimeStamp
FROM ISAlive 
WHERE RecordUpdatedDate <= NOW() - INTERVAL 10 MINUTE;


NOW() + INTERVAL 2 MINUTE
NOW() + INTERVAL 5 MINUTE               
NOW() + INTERVAL 10 MINUTE
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜