como saber si un afecha es mayor o menor js 1

como saber si un afecha es mayor o menor js

let date1 = new Date(2019, 08, 07, 11, 45, 55); 
let date2 = new Date(2019, 08, 03, 11, 45, 55); 
if (date1.getTime() < date2.getTime()) 
  document.write("date1 is lesser than date2"); 
else if (date1.getTime() > date2.getTime()) 
  document.write("date1 is greater than date2"); 
else
  document.write("both are equal"); 

Here is what the above code is Doing:
1. We are creating two Date objects.
2. We are comparing the time of both the objects using getTime() method.
3. If the time of date1 is less than date2, then date1 is lesser than date2.
4. If the time of date1 is greater than date2, then date1 is greater than date2.
5. If the time of both the objects are equal, then both are equal.

Similar Posts