Get Difference between 2 dates - Javascript Date Operation

Javascript examples for Date Operation:Date Compare

Description

Get Difference between 2 dates

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  ww w  .j  av  a  2s  . co  m*/

var date1 = new Date("09/07/2013");
var date2 = new Date("09/15/2015");
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
console.log(diffDays);

    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials