Reputation: 87
So I am having a problem with comparing two dates. Today is stored as 2016-04-17 and date is stored as the same just with minutes and seconds behind the date. today.getTime() doesn't seem to work even though I have stored today as a date. Appreciate the help.
function getAnswers() {
var Query = new Parse.Query(Surveys);
Query.include("survey");
var today = new Date().toJSON().slice(0, 10);
Query.find({
success: function(objects, results) {
for (var i = 0; i < objects.length; i++) {
var navn = objects[i].get("survey").get("name");
if (navn == "Trening") {
var query = new Parse.Query(SurveyAnswer);
query.descending("createdAt");
query.include("author");
query.equalTo("survey", objects[i]);
query.find({
success: function(results) {
for (var i in results) {
var date = results[i].get("createdAt");
console.log(date.getTime());
console.log(today.getTime());
if (date.getTime() === today.getTime()) {
console.log("Yay");
} else {
console.log("This didn't work");
}
}
Upvotes: 0
Views: 4536
Reputation: 179
var today = new Date().toJSON().slice(0, 10); --> after this, today is no longer a date object, it becomes a string which no longer has the getTime function.
Upvotes: 0
Reputation: 798
You need to convert date to a Date object.
var date = new Date(results[i].get("createdAt"));
Upvotes: 1