Find the difference in 2 date/times by day, hour, minutes and seconds.
/**
* Get the time difference between 2 dates in days
*/
function timeDayDifference(endDate,startDate) {
var difference = endDate.getTime() - startDate.getTime();
difference -= (Math.floor(difference/1000/60/60/24)*1000*60*60*24);
return difference;
}
/**
* Get the time difference between 2 dates in hours
*/
function timeHourDifference(endDate,startDate) {
var difference = endDate.getTime() - startDate.getTime();
difference -= (Math.floor(difference/1000/60/60)*1000*60*60);
return difference;
}
/**
* Get the time difference between 2 dates in minutes
*/
function timeMinuteDifference(endDate,startDate) {
var difference = endDate.getTime() - startDate.getTime();
difference -= (Math.floor(difference/1000/60)*1000*60);
return difference;
}
/**
* Get the time difference between 2 dates in seconds
*/
function timeSecondDifference(endDate,startDate) {
var difference = endDate.getTime() - startDate.getTime();
difference = Math.floor(difference/1000);
return difference;
}
var startDateTime = new Date(2010,5,10,8,0);
var endDateTime = new Date(2010,5,11,8,0);
var dayDiff = timeDayDifference(endDateTime,startDateTime) ;
var hourDiff = timeHourDifference(endDateTime,startDateTime);
var minDiff = timeMinuteDifference(endDateTime,startDateTime);
var secDiff = timeSecondDifference(endDateTime,startDateTime);