newbie
newbie

Reputation: 24625

How can I get reports for last 24h in SQL?

I need to get all reports made in last 24h, table has CreatedDate column, so I need to check in database that report was created in last 24h. I know I can use getdate() to get current date, but how can I minus 24h from that attrbiute and then compare that date with CretedDate?

Upvotes: 0

Views: 106

Answers (2)

shahkalpesh
shahkalpesh

Reputation: 33476

myDateTimeColumn BETWEEN GetDate() - 1 AND GetDate()

Upvotes: 1

Daniel Vassallo
Daniel Vassallo

Reputation: 344261

You can use the DATEADD() function as follows:

... WHERE CreatedDate > DATEADD(HOUR, -24, GETDATE())

Upvotes: 2

Related Questions