How to get the number of days between two Dates in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To get the number of days between two dates, use the Maths.floor() method.


You can try to run the following code to get days between two dates −

Live Demo

      <title>JavaScript Get Days</title>
         var date1, date2;
         date1 = new Date();
         date2 = new Date( "Dec 10, 2015 20:15:10" );
         // get total seconds between two dates
         var res = Math.abs(date1 - date2) / 1000;
         var days = Math.floor(res / 86400);
         document.write("<br>Difference: "+days);


Mon May 28 2018 09:32:56 GMT+0530 (India Standard Time)
Thu Dec 10 2015 20:15:10 GMT+0530 (India Standard Time)
Difference: 899
Published on 13-Feb-2018 13:42:10