comparing dates in 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 dates in javascript
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 3: string compare on date in js
var d1 = Date.parse("2012-11-01");
var d2 = Date.parse("2012-11-04");
if (d1 < d2) {
alert ("Error!");
}
Example 4: 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 5: javascript compare dates
let d1 = new Date();
let d2 = new Date();
d1 > d2
d1 >= d2
(d1 >= d2) && (d2 >= d1)
Example 6: 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);