Restrictions Between for Date in Hibernate Criteria

criteria.add(Restrictions.between("DATE(auditDate)", sDate, eDate)); use this for ignoring time from date.


I assume your auditDate is in fact a timestamp. If it's the case, then this is normal, because 25/05/2011 means 25/05/2011 at 0 o'clock (in the morning). So, of course, every row having an audit timestamp in the date 25/05/2011 is after 0 o'clock in the morning.

I would add 1 day to your end date, and use auditDate >= sDate and auditDate < eDate.

criteria.add(Restrictions.ge("auditDate", sDate)); 
criteria.add(Restrictions.lt("auditDate", eDate));

Tags:

Hibernate