Filter a date property between a begin and end Dates with JDOQL

Posted by Sergio del Amo on Stack Overflow See other posts from Stack Overflow or by Sergio del Amo
Published on 2010-03-02T13:36:52Z Indexed on 2010/03/18 19:51 UTC
Read the original article Hit count: 399

Filed under:

I want to code a function to get a list of Entry objects whose date field is between a beginPeriod and endPeriod I post below a code snippet which works with a HACK. I have to substract a day from the begin period date. It seems the condition great or equal does not work.

Any idea why I have this issue?

public static List<Entry> getEntries(Date beginPeriod, Date endPeriod) {
/* TODO 
 * The great or equal condition does not seem to work in the filter below
 * Substract a day and it seems to work 
 */
Calendar calendar = Calendar.getInstance();
calendar.set(beginPeriod.getYear(), beginPeriod.getMonth(), beginPeriod.getDate() - 1);
beginPeriod = calendar.getTime();

PersistenceManager pm = JdoUtil.getPm();
Query q = pm.newQuery(Entry.class);     
q.setFilter("this.date >= beginPeriodParam && this.date <= endPeriodParam");
q.declareParameters("java.util.Date beginPeriodParam, java.util.Date endPeriodParam");         
List<Entry> entries = (List<Entry>) q.execute(beginPeriod,endPeriod);
return entries;
}

© Stack Overflow or respective owner

Related posts about jdoql