开发者

Get records 10 min before system datetime in SQL

开发者 https://www.devze.com 2023-02-09 13:09 出处:网络
i need to find the records 10 min before system cu开发者_JAVA技巧rrent datetime. select Id,TimeStamp from ISAlive where RecordUpdatedDate < GETDATE() --SYSDATETIME()

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

精彩评论

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

关注公众号