Online Shopping : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

26 of 28 people (93%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

how can i find the days difference, between 2 dates in javascript???

Apr 5th, 2008 20:30
ha mo, Colin Fraser, Ram kathir, unknown


I think I got this from an earlier question in FAQTS: 
<script language="JavaScript"><!--
function timeDifference(laterdate,earlierdate) {
    var difference = laterdate.getTime() - earlierdate.getTime();
    var daysDifference = Math.floor(difference/1000/60/60/24);
    difference -= daysDifference*1000*60*60*24
    var hoursDifference = Math.floor(difference/1000/60/60);
    difference -= hoursDifference*1000*60*60
    var minutesDifference = Math.floor(difference/1000/60);
    difference -= minutesDifference*1000*60
    var secondsDifference = Math.floor(difference/1000);
    document.write('difference = ' + daysDifference + ' day/s ' +
hoursDifference + ' hour/s ' + minutesDifference + ' minute/s ' +
secondsDifference + ' second/s ');
}
var laterdate = new Date(2003,0,1);     // 1st January 2003
var earlierdate = new Date(2001,8,6);  // 6th September 2001
timeDifference(laterdate,earlierdate);
//--></script>
It is supposed to work.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com