This is the code that is written to evaluate the desired result:
Calendar c7DaysAgo = Calendar.getInstance(); // 7 days ago
c7DaysAgo.add(Calendar.DATE, -7);
Calendar today = Calendar.getInstance(); // today
today.add(Calendar.DATE, 0);
Criteria criteria = session.createCriteria(Checkin.class)
.add(Restrictions.like("fbuid", id))
.add(Restrictions.between("date", today.getTime(), c7DaysAgo.getTime()));
List<Checkin> checkinList = criteria.list();
return checkinList.size();
The table values that is being hit to retrieve the values is:
| id | date |fbuid | number |
| 1 |2012-12-04 18:41:34 | 1111 | 16 |
| 2 |2012-12-04 18:41:34 | 1111 | 2 |
I need the count of rows that fall between today and 7 days before.
But I am getting a value 0 instead of 2.
please help me as i cannot figure out what is going wrong!
I realized my mistake….the parameters for between were in the wrong order…it should be