Ramesh V
Ramesh V

Reputation: 259

Google app engine java filtering date query with day

I am looking for some thing like this.

public class User 
{
   private Date createdOn;
}

Now i need a query to fetch users created on day 10th of any month or year. Like i need users created on 10th Jan 2012, 10th Feb 2012, 10th June 2010..... How can i get part of a date in gae query?

Thanks,

Ramesh.V

Upvotes: 1

Views: 1440

Answers (2)

Ian Marshall
Ian Marshall

Reputation: 760

For your filter, you could use:

"(createdOn >= p1) && (createdOn <= p2)"

where you have set the parameters p1 and p2 to be the start and finish Dates of the day in question.

Upvotes: 1

Rick Mangi
Rick Mangi

Reputation: 3769

Just create a date object for whatever date you're looking for and use it as part of the query. There's nothing special about Dates in queries.

Not sure if you're using JDO, JPA or the datastore directly, but either way

See the GQL reference (not really python specific): http://code.google.com/appengine/docs/python/datastore/gqlreference.html

SELECT * FROM User WHERE createdOn == :date

In JDO it would look something like:

Query query = pm.newQuery(User.class);
query.setFilter("createdOn == dateParam");
List<User> results = (List<User>) query.execute(date);

Upvotes: 3

Related Questions