Skip to content
Advertisement

How to retrieve records for last 30 minutes in MS SQL?

I want to retrieve records for last 30 minutes in a table. How to do that? Below is my query..

select * from
[Janus999DB].[dbo].[tblCustomerPlay]
where DatePlayed < CURRENT_TIMESTAMP
and DatePlayed >
(CURRENT_TIMESTAMP-30)

Advertisement

Answer

Change this (CURRENT_TIMESTAMP-30)

To This: DateADD(mi, -30, Current_TimeStamp)

To get the current date use GetDate().

MSDN Link to DateAdd Function
MSDN Link to Get Date Function

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement