如何在HQL中过滤过去24小时内的日期时间值?

发布于 2024-09-08 21:18:32 字数 87 浏览 3 评论 0原文

我还没有找到明确的答案,但我想获取过去 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏辞 2024-09-15 21:18:32

您不需要 datediff,因为您已经知道 24 小时前是什么时间。

这是一个 Linq (NH 3.x) 示例:

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

如果您使用 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:

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文