How to filter datetime values in past 24 hours in HQL?
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)
精彩评论