I have a table in a MySQL DB with a date(DATETIME)
column on it. How do I express it in java Hibernate criteria if let's say I would like to query for records where NOW() < ('date' + 1 day)
?
You could turn it the other way around and compare 'date' >= (NOW - 1 day)
.
Assuming you've got a mapped MyTable
class with the date
property:
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, -1);
Criteria criteria = session.createCriteria(MyTable.class);
criteria.add(Restrictions.ge("date", c.getTime());
List results = criteria.list();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With