如何在HQL中过滤过去24小时内的日期时间值?
我还没有找到明确的答案,但我想获取过去 24 小时内的任何值。我在代码中有一个替代解决方案,但我想看看是否有相当于使用 t-sql datediff 的解决方案
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-sql datediff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要 datediff,因为您已经知道 24 小时前是什么时间。
这是一个 Linq (NH 3.x) 示例:
如果您使用 HQL,您可以使用
current_timestamp
等标准函数获取数据库服务器时间(作为练习,但如果您需要,我会添加它)它)You don't need datediff, because you already know what time it was 24hs ago.
Here's a Linq (NH 3.x) example:
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)