Compare dates from an array object with the current date. the current date is taken from MongoDB.
{"specialData": [
{
"content": {
"dateAdded": "2017-12-26T22:21:37+00:00"
}
},
{
"content": {
"dateAdded": "2018-01-12T22:21:37+00:00"
}
}
]
}
compare the content.dateAdded from the array object with the current date coming from MongoDB. current date coming from catalogue.metaData.lastUpdatedDate
let result = _.find(rokuFeeds.tvSpecials, function (n) {
if (new Date(n.content.dateAdded) < new Date(catalogue.metaData.lastUpdatedDate)) {
return true;
}
});
I’m trying like this
2
Answers
You can use
new Date(obj.specialData[0].content.dateAdded);
to convert string to date object.output
You can compare dates by using
getTime()
method.Now simply compare them, using comparison operators
> < >= <=