I have a list of dates in the format "2021-02-25T12:30:00" and I want to filter out those that are at least 24 hours ahead. The code snippet below attempts to achieve this, but seems to have an issue.
const date2 = "2021-02-26T12:30:00";
function getFormattedDate() {
const currentDate = new Date();
const formattedDate = `${currentDate.getFullYear()}-${currentDate.getMonth() + 1}-${currentDate.getDate()}T${currentDate.getHours()}:${currentDate.getMinutes()}:${currentDate.getSeconds()}`;
return formattedDate;
}
if ((Math.abs(new Date(date2.slice(-8)) - new Date(getFormattedDate().slice(-8))) / 36e5) >= 24) {
console.log("There's enough time");
} else {
console.log("Not enough time remaining");
}
console.log(date2.slice(-8));
Could someone point out the error in the code?