开发者

How to filter datetime values in past 24 hours in HQL?

开发者 https://www.devze.com 2023-01-06 19:50 出处:网络
I haven\'t found a clear answer but I would like to grab any values from within the past 24 hours. I have an alternative solution in code but I would like to see if there is an equivalent to using t-s

I haven't found a clear answer but I would like to grab any values from within the past 24 hours. I have an alternative solution in code but I would like to see if there is an equivalent to using t-sq开发者_C百科l datediff


You don't need datediff, because you already know what time it was 24hs ago.

Here's a Linq (NH 3.x) example:

session.Query<Foo>()
       .Where(f => f.DateAndTime >= DateTime.Now.AddDays(-1))

If you use HQL, you can get the DB server time with standard functions like current_timestamp (left as an exercise, but I'll add that if you need it)

0

精彩评论

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

关注公众号