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
精彩评论