xkm xkm - 1 year ago 56
Java Question

Ordering Query results by Date (String) for GAE

I have thousands of Entities stored in the GAE datastore where a field "create" is saved as a date

(standard format).

My question would be, is it still possible to do a
like this:

Query q = new Query("Post")
.addSort("created", SortDirection.DESCENDING);

Where "
" is actually a date String, stored like this:
2014-12-11T14:31:43 -08:00"

and actually get a descending order. I've tried it but the result set is just as random and not even in order by date.

Is there a way to tweak a GAE
to achieve this with this data?

Answer Source

Even if GAE has indexed date as string so '2014-12-11T14:31:43 -08:00' comes after '2014-12-04T14:31:43 -08:00' (just for example) which means natural sorting order should follow.

Have you indexed 'created' field? If not, GAE is gonna ignore the sort order you gave in query.