Calculate the days between two dates : Date Calculation « Date Time « JavaScript DHTML






Calculate the days between two dates

  

<html>
<head>
    <title>the date</title>
</head>
<body>
    <p id="dateField">&nbsp;</p>
    
    <script type = "text/javascript">
    var today = new Date();
    var then = new Date();

    then.setFullYear(3000,1,1);
    
    var diff = then.getTime() - today.getTime();
    
    diff = Math.floor(diff / (1000 * 60 * 60 * 24));
    
    var dateLoc = document.getElementById("dateField");
    
    dateLoc.innerHTML = diff + " days";
    </script>

</body>
</html>

   
    
  








Related examples in the same category

1.Date Object Calculations
2.Get your timezone
3.Append date to string
4.Putting a Time Stamp on a Page