开发者

Query by datetime in JDOQL / Java / GAE

开发者 https://www.devze.com 2022-12-23 04:43 出处:网络
I\'m working on a GAE app. I want to query datastore and retrieve all records between startDate and endDate. Each record has a datetime field. I\'m using a query similar to this (the below code is som

I'm working on a GAE app. I want to query datastore and retrieve all records between startDate and endDate. Each record has a datetime field. I'm using a query similar to this (the below code is something I quickly grabbed - I'm not near my developer machine.):


Query query = pm.newQuery(Employee.class);
query.setFilter("lastName == lastNameParam");
query.setOrdering("hireDate desc");
query.declareParameters("String lastNameParam");

try {
    List results = (List) query.execute("Smith");
    if (re开发者_运维知识库sults.iterator().hasNext()) {
        for (Employee e : results) {
            // ...
        }
    } else {
        // ... no results ...
    }
} finally {
    query.closeAll();
}

How do I have to format the date to form a correctly working query? How is the datetime stamp stored in datastore? As timestamp? Fully formatted? I can't find ANY information on this. Please help.


According to google datastore low-level API, Date Objects seems to be freely storable in GAE. As a consequence, using java.util.Date (or javax.sql.Date, it's not totally explicit) will do the job, i think.


You can also use timestamp

query.setFilter("hiredate>1700215218");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号