1var date1 = new Date('December 25, 2017 01:30:00');
2var date2 = new Date('June 18, 2016 02:30:00');
3
4//best to use .getTime() to compare dates
5if(date1.getTime() === date2.getTime()){
6 //same date
7}
8
9if(date1.getTime() > date2.getTime()){
10 //date 1 is newer
11}
1var date1 = new Date('December 25, 2017 01:30:00');
2var date2 = new Date('June 18, 2016 02:30:00');
3
4//best to use .getTime() to compare dates
5if(date1.getTime() === date2.getTime()){
6 //same date
7}
8
9if(date1.getTime() > date2.getTime()){
10 //date 1 is newer
11}
1var isLarger = new Date("2-11-2012 13:40:00") > new Date("01-11-2012 10:40:00");
2
1// solution is convert date to time by getTime()
2start = startDate.getTime();
3end = endDate.getTime();
4current = date.getTime();
5
6if (start <= current && current <= end) {
7 // do something here
8}
1let myDate = new Date("January 13, 2021 12:00:00");
2let yourDate = new Date("January 13, 2021 15:00:00");
3
4if (myDate < yourDate) {
5 console.log("myDate is less than yourDate"); // will be printed
6}
7if (myDate > yourDate) {
8 console.log("myDate is greater than yourDate");
9}
1let d1 = new Date();
2let d2 = new Date();
3// can use >, <, <=, <=
4d1 > d2
5d1 >= d2
6// == won't work so can use this:
7(d1 >= d2) && (d2 >= d1)