I have a date like this in DB:
2020-10-21T00:06:06.000Z
which I want to compare with current date and time
If current date and time has past the date from DB then trigger some action.
let oldDate = `2020-10-21T00:06:06.000Z`;
let dateNow = new Date();
console.log('oldDate ', new Date(oldDate));
console.log('date now', dateNow);
console.log('oldDate time', new Date(oldDate).getTime());
console.log('newDate time', dateNow.getTime());
const schedule = dateNow.getTime() > new Date(oldDate).getTime() ? "trigger now" : "trigger later";
console.log('scheduled for: ', schedule);
I am trying to check if dateTime is past old dateTime but is this is right approach or any other better solutions?