Date Difference Calculation:   Return to List

' In JavaScript, you can easily get the difference between two dates. This is because when you create a date object, it's automatically converted to a number, specifically, the number of milliseconds passed since 1/1/1970 GMT to the date. So here's an example that shows how many days have passed since January 1st, 1998:

<script language="javascript">
var today=new Date()
var day1998=new Date(1998,0,1)
var difference=today-day1998' //unit is milliseconds
formatdifference=Math.round(difference/1000/60/60/24)' //now unit is days
document.write(formatdifference)
</script>



Note to Webmaster