comparing two dates javascript code example
Example 1: compare dates in js
var date1 = new Date('December 25, 2017 01:30:00');
var date2 = new Date('June 18, 2016 02:30:00');
if(date1.getTime() === date2.getTime()){
}
if(date1.getTime() > date2.getTime()){
}
Example 2: compare date and time in js
var isLarger = new Date("2-11-2012 13:40:00") > new Date("01-11-2012 10:40:00");
Example 3: 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");
}