使用 JDOQL 过滤开始日期和结束日期之间的日期属性

发布于 2024-08-23 15:38:40 字数 969 浏览 8 评论 0原文

我想编写一个函数来获取 Entry 对象的列表,其 date 字段位于 beginPeriodendPeriod 之间我在下面发布了一个与 HACK 一起使用的代码片段。我必须从开始日期中减去一天。看来伟大或等于的条件不起作用。

知道为什么我会遇到这个问题吗?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨敛清荷 2024-08-30 15:38:40

我的猜测是因为数组从 0 开始。我试图你的(我的查询没有返回任何内容??)并注意到它已经持续了几个月 - 1 =>;二月,4=>五月,等等。

my guess is it's because arrays begin at 0. i was trying to your (my query doesn't return anything??) and noticed that it's true for months - 1 => february, 4=>may, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文