Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare dates with Parse.com

I'm trying to compare some dates for a ParseQuery. It doesn't give me errors but it just doesn't filter the dates. Here's some code:

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

date is 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 my ParseObjects on parse.com, I see the objects got a dateFrom and dateTo.

Can somebody tell me why it doesn't filter? Thank you

like image 660
dumazy Avatar asked May 21 '12 13:05

dumazy


1 Answers

I've tested that Date Comparisons work with the Javascript SDK.

(word is a basic parse model)

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 could always transfer your days into seconds like Date.getTime() and use integers for the comparison.

regards

like image 71
Danielito Avatar answered Oct 04 '22 01:10

Danielito