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

Q2 How can I calculate the number of days elapsed between two dates?

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

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

function daysElapsed(date1,date2) {
    var difference =
        Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0)
      - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
    return difference/1000/60/60/24;
}

document.write(daysElapsed(new Date(2000,0,1),new Date(1999,11,31)));
//--></script>

Feedback on 'Q2 How can I calculate the number of days elapsed between two dates?'

©2018 Martin Webb