javascript add date compare code example
Example 1: how to compare dates js
const x = new Date('2013-05-22');
const y = new Date('2013-05-23');
console.log('x < y', x < y);
console.log('x > y', x > y);
console.log('x === y', x === y);
console.log('+x <= +y', +x <= +y);
console.log('+x >= +y', +x >= +y);
console.log('+x === +y', +x === +y);
Example 2: javascript compare dates
let myDate = new Date("January 13, 2021 12:00:00");
let yourDate = new Date("January 13, 2021 15:00:00");
if (myDate < yourDate) {
console.log("myDate is less than yourDate");
}
if (myDate > yourDate) {
console.log("myDate is greater than yourDate");
}