简体   繁体   English

在Hibernate中查询日期和时间跨度

[英]Query with date and timespan in Hibernate

I want to use Hibernate to query with the condition like where A.beginTimestamp + A.timespan > current_timestamp() . 我想使用Hibernate来查询类似where A.beginTimestamp + A.timespan > current_timestamp()

The beginTimestamp is a timestamp column and A.timespan is the time span in seconds. beginTimestamp是一个时间戳列,而A.timespan是以秒为单位的时间跨度。

How to do this in Hibernate? 在Hibernate中如何做到这一点?

Thanks! 谢谢!

Consider using the function TIMESTAMPDIFF in the where clause from the query in your DAO. 考虑在DAO中的查询的where子句中使用TIMESTAMPDIFF函数。 Its signature is: 它的签名是:

TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2): Returns the integer difference between datetime_expr1 and datetime_expr2 TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2):返回datetime_expr1和datetime_expr2之间的整数差

The unit for the result is given by the unit argument. 结果的单位由unit参数指定。

The unit should be one of the following values: 单位应为以下值之一:

FRAC_SECOND,
SECOND,
MINUTE,
HOUR,
DAY,
WEEK,
MONTH,
QUARTER, or
YEAR.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM