i need to find the records 10 min before system current datetime.
select Id,TimeStamp from ISAlive where RecordUpdatedDate < GETDATE() --SYSDATETIME()
Here's the SQL query to select records for last 10 minutes. In the above query we select those records where order_date falls after a past interval of 10 minutes. We use system function now() to get the latest datetime value, and INTERVAL clause to calculate a date 10 minutes in the past.
SELECT col1, col2, col3 FROM table WHERE DATE_ADD(last_seen, INTERVAL 10 MINUTE) >= NOW(); This adds 10 minutes to last_seen and compares that against the current time. If the value is greater, last_seen is less than ten minutes ago. See the documentation on DATE_ADD() for an explanation of how it is used.
How do I get last 30 minutes data in SQL? SQL Server uses Julian dates so your 30 means "30 calendar days". getdate() – 0.02083 means "30 minutes ago".
SQL Server GETDATE() Function The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss.mmm' format. Tip: Also look at the CURRENT_TIMESTAMP function.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With