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
精彩评论