0

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;
}
4

1 回答 1

0

我的猜测是因为数组从 0 开始。我正在尝试您的(我的查询没有返回任何内容??)并注意到几个月都是如此 - 1 => 2 月,4 => 5 月等。

于 2010-03-18T19:48:04.307 回答