I'm trying to get the difference in days between today and a date stored in my MongoDB database with ISO format, how can I do this? Thanks in advance.
let ISOdate = ISODate("2020-12-25T20:40:08.295Z")
let difference = newDate() - ISOdate;
if (difference > 45 days) { return ok }
ISODate is just a wrapper on the JavaScript Date object, so you can use the Date methods to determine the time difference between two dates.
const dbDate = ISODate("2020-12-25T20:40:08.295Z");
const nowDate = new Date();
const msDifference = nowDate.getTime() - dbDate.getTime();
const daysDifference = Math.floor(msDifference / (1000 * 60 * 60 * 24));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.