开发者

hibernate HQL date difference

I want to find all records which maps to object XYZ with following conditions A has date field XyzDateTime (its a time stamp) Now currentTime -xyzDateTime > 20 i want to select the record

query = session.creatQuery(Select x from XYZ where :currentTime-xyzDateTime > 20 )
query.setParameter("currentTime",new Date())
开发者_高级运维

is this correct?

Can i check date difference in this way?


It's not correct. Simplest solution is like that (not the prettiest solution at all)

Date twentyDaysInFuture = new Date(Calendar.getInstance().add(Calendar.DAY_OF_MONTH, 20).getTime());

query = session.createQuery("SELECT x FROM XYZ x WHERE xyzDateTime > :endDate").setParameter("endDate", twentyDaysInFuture);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜