How to Get Last 5 Minutes of Data with Datetime Data Type in Sql Server

I would like to run a query against data that is being consumed by an Esri ArcGIS Server SQL Server database, the data reads as 4/15/2015 4:21:45 PM when I use

SELECT * 
FROM ServiceRequest.DBO.History_Table 
WHERE: Time = CONVERT(DATE, GETDATE())

I return all records with today's date, but how would I extend this so that I retrieve the last 5 minutes? My History_Table column is a date data type.

2

1 Answer

You should query from the parameter less five minutes using the DATEADD function

Then use the minutes parameter

WHERE [dateColumn] > DATEADD(minute, -5,  GETUTCDATE())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest