[thelist] JS calculations on Date object

fstorr fffrancis at fstorr.demon.co.uk
Mon Sep 30 13:00:01 CDT 2002


The getTime() method returns the number of milliseconds since 1 January
1970 for the given date object. By subtracting this value for the
current date from the equivalent value for the expiry date, and dividing
the result by the number of milliseconds in a day, we get the difference
in days between the two dates. We use Math.floor() to round the number
of days down to the nearest whole number.

You can then use daysLeft in a document.write() call to output the
number of days remaining!

I hope this helps!

Regards,

Steve

+++++++++++++++++++++++++++


Cheers for that Steve and also for the explanation - very helpful.  One
question - if I set todaysDate and expireDate to the same day, daysLeft
is equal to -1.  Shouldn't this be 0 (and if so, I'll whack a +1 at the
end of the line)?

Thanks

Francis





More information about the thelist mailing list