I wrote a function to calculate the amount of days that separate two dates. I have to calculate it in milliseconds from the 1st of January 1970 because the dates can be in different month.
Now I found out that the function returns wrong results when the dates are in different month?! Seems like the internal calender of javascript is wrong!? Any advices!?
[CODE]
<HTML>
<HEAD>
<SCRIPT LANGUAGE=”JavaScript”>
var date1 = new Date(2004, 5, 30);
var date2 = new Date(2004, 6, 1);
function difference(){
var dtime = date1.getTime();
var d2time = date2.getTime();
var diff = d2time – dtime;
var diffstring = (diff/1000) + ” seconds”;
diffstring += ” or ” + (diff/(1000*60)) + ” minutes”;
diffstring += ” or ” + (diff/(1000*60*60)) + ” hours”;
diffstring += ” or ” + (diff/(1000*60*60*24)) + ” days”;
document.write(“Timedifference: ” + diffstring);
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE=”JavaScript”>
difference();
</SCRIPT>
</BODY>
</HTML>