How can I get reports for last 24h in SQL?
I need to get all reports made in last 24h, 开发者_Python百科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?
You can use the DATEADD()
function as follows:
... WHERE CreatedDate > DATEADD(HOUR, -24, GETDATE())
myDateTimeColumn BETWEEN GetDate() - 1 AND GetDate()
精彩评论