How to compare two JavaScript Date Objects?

To compare two date objects with JavaScript, create two dates object and get the recent date to compare it with the custom date.


You can try to run the following code to compare two dates −

Live Demo

<!DOCTYPE html>
         var date1, date2;
         date1 = new Date();
         date2 = new Date( "Dec 10, 2015 20:15:10" );
         if (date1 > date2) {
            document.write("<br>Date1 is the recent date.");
         } else {
            document.write("<br>Date 2 is the recent date.");


Mon May 28 2018 09:48:49 GMT+0530 (India Standard Time)
Thu Dec 10 2015 20:15:10 GMT+0530 (India Standard Time)
Date1 is the recent date

Updated on: 18-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started