»
EnglishFrenchVietnamese

Print - Days Between Two Dates script - JavaScriptBank.com

Full version: jsB@nk » Time » Counter » Days Between Two Dates script
URL: https://www.javascriptbank.com/days-between-two-dates-script.html

Days Between Two Dates script © JavaScriptBank.comUse this JavaScript to figure out how many days there are between two given dates. Very easy to implement.

Full version: jsB@nk » Time » Counter » Days Between Two Dates script
URL: https://www.javascriptbank.com/days-between-two-dates-script.html



JavaScript
<script type="text/javascript">// Created by: JavaScript Demos :: http://www.javascript-demos.com/function calcDays(){  var date1 = document.getElementById('d1').lastChild.data;  var date2 = document.getElementById('d2').lastChild.data;  date1 = date1.split("-");  date2 = date2.split("-");  var sDate = new Date(date1[0]+"/"+date1[1]+"/"+date1[2]);  var eDate = new Date(date2[0]+"/"+date2[1]+"/"+date2[2]);  var daysApart = Math.abs(Math.round((sDate-eDate)/86400000));  document.getElementById('diffDays').innerText = daysApart;}onload=calcDays;</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<table width='220' border='1' cellspacing='0' cellpadding='5' align="center"><tr><td>Starting<br>Date</td><td>Ending<br>Date</td><td>Total<br>Days</td></tr><tr><td id='d1'>01-01-2006</td><td id='d2'>08-05-2006</td><td id='diffDays' align='center'></td></tr></table><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->