Select (Get) last two hours records from database table in SQL Server

rani
 
on Apr 22, 2021 10:39 PM
846 Views

How to select last 2 hours records from database in sql server

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Apr 22, 2021 11:57 PM

Hi rani

Refer below sample query.

SQL

SELECT *
FROM Customers
WHERE [Date] >= DATEADD(HOUR, -2, GETDATE()) AND [Date] <= GETDATE()
ORDER BY [Date] ASC

-- OR
SELECT *
FROM Customers
WHERE [Date] BETWEEN DATEADD(HOUR, -2, GETDATE()) AND GETDATE()
ORDER BY [Date] ASC