[thelist] JS calculations on Date object

fstorr fffrancis at fstorr.demon.co.uk
Mon Sep 30 12:13:05 CDT 2002

Hi all

I'm working on a JavaScript solution to expire some pages.  Once a
certain date has arrived, the page will have expired and the user will
be redirected to a "the page you're trying to view has expired" page.
However, to try and be a little more helpful, I'd like to show a message
on the screen that says something like "this page will expire in 5 days
- please contact the document owner".  I've got part of the way there,
but I can't work out how to take 2 dates away from each other to give a
value left in days.  So far, I've got this, which works:

function checkexpired()
var expireDate
var todaysDate

expireDate = new Date("September 28, 2002") //this is the date the page

todaysDate = new Date()  //this is today's date

if (todaysDate > expireDate)
location.href="http://www.foo.com" //this is the redirection page

Can someone point me in the direction of the rest?



More information about the thelist mailing list