【问题标题】:Hibernate: how to get time gap between two Date columns?Hibernate:如何获得两个日期列之间的时间间隔?
【发布时间】:2015-05-01 17:26:42
【问题描述】:

例如,我的列看起来像

1990-02-13 00:00:00.0 和 2015-02-19 00:00:00.0。

我怎样才能得到以天为单位的时间间隔(差异)?

【问题讨论】:

    标签: java hibernate date criteria restriction


    【解决方案1】:

    如果你使用 MySQL dialect for Hibernate,你可以使用以下函数,

    unix_timestamp(datetime_value) - 取两列之间的差

    current_date() 获取当前日期。 参考函数列表可以在这里找到

    https://hibernate.atlassian.net/secure/attachment/11953/MySQLDialect.java

    对于第二个问题,您可以尝试使用

    criteria.add( Restrictions.le("date_column", current_date() ) )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多