<script language="javascript">
function daysbetweenDates()
{
var iY=document.getElementById("iY").value;
var iM=document.getElementById("iM").value;
var iD=document.getElementById("iD").value;
var fY=document.getElementById("fY").value;
var fM=document.getElementById("fM").value;
var fD=document.getElementById("fD").value;
start = new Date(iY,iM,iD);
end = new Date(fY,fM,fD);
var t2 = end.getTime();
var t1 = start.getTime();
diff = t2 - t1;
result = Math.floor(diff/(1000*60*60*24));
alert(result + " days online");
}
</script>
Start (YYY/MM/DD):<br>
<input type="text" id="iY">
<input type="text" id="iM">
<input type="text" id="iD">
End (YYY/MM/DD):<br>
<input type="text" id="fY">
<input type="text" id="fM">
<input type="text" id="fD"><br>
<a href="#" onclick="daysbetweenDates();">Calculate</a>
Notes about programming on iPhone, iPad, C#, PHP, data science and other things.
Thursday, December 10, 2009
How calculate days between two dates using javaScript
Yesterday, I needed to calculate the days between two different dates so I decided to do it using javaScript. Here is my example:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment