Page 1 of 1

countdown

Posted: Sat Apr 23, 2011 3:04 pm
by Vegan
On my IT home page, http://www.windows-it.tk I have the expiry dates manually entered into a table.

So why not mechanize the table with a date calculation in JavaScript

XP expires April 8, 2014 which is 1080 days from now, obviously if it is expired the cell should say so

I have other versions of Windows listed and they have differing dates that need to be altered as well

Code: Select all

function days_between(date1, date2) {
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24;
    // Convert both dates to milliseconds
    var date1_ms = date1.getTime();
    var date2_ms = date2.getTime();
    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms);
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY);
}


Any helpful code snippets I can leverage?