开发者

how to find date difference result in minutes

开发者 https://www.devze.com 2023-03-27 09:00 出处:网络
I have a date field in my table.Now i want to check if currentTime -DbDatetime > xminutes.How can i do开发者_运维问答 it in sql hibernate

I have a date field in my table.Now i want to check if currentTime -DbDatetime > xminutes.How can i do开发者_运维问答 it in sql hibernate

query = session.creatQuery(Select x from Xabc where :currentTime- abcDateTime > 20 )
query.setParameter("currentTime",new Date())


I suppose that the easy way is to calculate it in Java, as for example

new Date( new Date().getTime() - (20 * 60000));

I also found in Google the following snippet

from ApplData data where (day(current_date()) - day(data.myDate)) > 15 

It seems that you can use expressions with date functions and Hibernate has plenty of them

current_date(), current_time(), current_timestamp(), second(...), minute(...), hour(...), day(...), month(...), year(...)

Refer to the manual

0

精彩评论

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