开发者

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

开发者 https://www.devze.com 2023-01-01 09:04 出处:网络
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

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()
0

精彩评论

暂无评论...
验证码 换一张
取 消