Compare dates with Parse.com

I am trying to compare some dates for ParseQuery. It does not give me errors, but it just does not filter the dates. Here is the code:

if(dateFrom!=null){ query.whereLessThanOrEqualTo("from", dateFrom); } if(dateTo!=null){ query.whereGreaterThanOrEqualTo("to", dateTo); } 

date - java.util.Date (not sql)

 Date dateFrom = new Date(fromYear,fromMonth,fromDay,fromHour,fromMinute); Date dateTo = new Date(toYear,toMonth,toDay,toHour,toMinute); 

when I look at ParseObjects on parse.com, I see that the objects received the date and time.

Can someone tell me why it is not filtering? Thanks you

+6
source share
1 answer

I tested that date comparison works with the Javascript SDK.

(the word is the basic model of analysis)

 var d = new Date(); var word = new Word(); word.set("dateTo", new Date (2012, 01, 01)); word.save(); var dateTo = new Date (2012, 12, 31); var query = new Parse.Query(Word); query.greaterThan("dateTo", dateTo); query.find({ success: function(results) { alert("Successfully retrieved " + results.length + " scores."); }, error: function(error) { alert("Error: " + error.code + " " + error.message); } }); 

As a workaround, you can always wrap your days in seconds, like Date.getTime (), and use integers for comparison.

considers

+3
source

Source: https://habr.com/ru/post/916253/


All Articles