I want to compare the date with MongoDB and my date.
I also read this and this , and I did not find the answer.
My code is:
today: function() { var today = moment().format(); return Posts.find({createdAt : { $gte : today}})
As a result, this construct does not work, but if I compare this:
var today = moment().format(); var daystart = moment().startOf('day').format(); if (daystart > today){ console.log ("YES"); } else if (daystart < today)console.log ("NO");
Return
"NO"
Can anybody help?
EDIT:
today: function() { var today = moment().toDate(); var daystart = moment().startOf('day').toDate(); // console.log(today + daystart); return Posts.find({createdAt : { $gt : today}}) }, week: function() { var today = new Date(); return Posts.find({createdAt : { $lt : today}}) }, month: function() { var today = new Date(); return Posts.find({createdAt : { $ne : today}}) } createdAt = new Date();
mongodb momentjs
nl pkr
source share