Jack Goh
Jack Goh

Reputation: 36

Parse Android query for objects created within month

I wanted to query object within December but it return with Jan-Nov object. This is my query.

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.MONTH, 0);
Date date = calendar.getTime();

Log.d("date", String.valueOf(date));
ParseQuery<ParseObject> query = ParseQuery.getQuery("Post");
query.whereGreaterThanOrEqualTo("createdAt", date);
query.count();

List<ParseObject> results = null;
results.size(); //this count include the whole year value

Upvotes: 0

Views: 347

Answers (1)

Kostantinos Ibra
Kostantinos Ibra

Reputation: 126

First of all try this :

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 0);
calendar.set(Calendar.MONTH, 0);

You need to fetch all data for just 1 year ( Year start Jan 1 and end Dec 31 ) and not more.And maybe that's the reason it stack there.

Also you don't need than line of code :

Date date = calendar.getTime();

Try just this :

query.whereGreaterThanOrEqualTo("createdAt", calendar.getTime());

I hope it help you.

Upvotes: 1

Related Questions