Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q368 How can you display how many days are left until 31/12/1999?

You are here: irt.org | FAQ | JavaScript | Date | Q368 [ previous next ]

<SCRIPT LANGUAGE="JavaScript"><!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function timeTillDate(whenDay,whenMonth,whenYear) {
    var now = new Date();
    var then = new Date(y2k(whenYear),whenMonth-1,whenDay);

    var difference = Date.UTC(y2k(then.getYear()),then.getMonth(),then.getDate(),0,0,0) -
                     Date.UTC(y2k(now.getYear()),now.getMonth(),now.getDate(),0,0,0);

    return difference/(1000*60*60*24);
}

document.write(timeTillDate(31,12,1998));
//--></SCRIPT>

©2018 Martin Webb