Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get records 10 min before system datetime in SQL

i need to find the records 10 min before system current datetime.

select Id,TimeStamp from ISAlive where RecordUpdatedDate < GETDATE() --SYSDATETIME()
like image 763
gofor.net Avatar asked Feb 10 '11 12:02

gofor.net


People also ask

How do I get last 10 minutes in SQL?

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.

How do you SELECT all records that are 10 minutes with current timestamp in SQL Server?

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?

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".

How do I get system time in SQL query?

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.


4 Answers

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
like image 167
Thomas Rushton Avatar answered Oct 12 '22 14:10

Thomas Rushton


SELECT Id, TimeStamp
FROM ISAlive 
WHERE RecordUpdatedDate < DATEADD(minute,-10, SYSDATETIME());
like image 39
Skorpioh Avatar answered Oct 12 '22 14:10

Skorpioh


You can do this with now()

SELECT Id, TimeStamp
FROM ISAlive 
WHERE RecordUpdatedDate <= NOW() - INTERVAL 10 MINUTE;
like image 4
Oli Girling Avatar answered Oct 12 '22 14:10

Oli Girling


NOW() + INTERVAL 2 MINUTE
NOW() + INTERVAL 5 MINUTE               
NOW() + INTERVAL 10 MINUTE
like image 2
Rahman Qadirzade Avatar answered Oct 12 '22 16:10

Rahman Qadirzade