我必须比较休眠hql查询中的两个日期。我在我的Java bean中使用java.util.Date,并在MySQL数据库中将时间戳用作数据类型。
select t from Task t where t.modifiedDate > t.endDate;
上面的查询将时间与日期进行比较。我应该怎么做才能在没有时间的情况下比较上述查询中的日期。
有关可用的日期功能,请参见Hibernate文档。
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html
在第14.10节中注意这一行
second(...), minute(...), hour(...), day(...), month(...), and year(...)
所以这应该工作
... where year(t.endDate) > year(t.startDate)
and month(t.endDate) > month(t.startDate)
and day(t.endDate) > day(t.startDate)
报告为满足问题的解决方案是
... where DATE(t.endDate) > (t.startDate)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句