function timeDifference(startDate,endDate)
{

date1 = startDate;
date2 = endDate;

laterdate = date1.split(“-“);
laterY=laterdate[0];
laterM=laterdate[1];
laterD=laterdate[2];

earlierdate = date2.split(“-“);
earlierY=earlierdate[0];
earlierM=earlierdate[1];
earlierD=earlierdate[2];

var laterdate = new Date(laterY,laterM,laterD);
var earlierdate = new Date(earlierY,earlierM,earlierD);

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);

return daysDifference;

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.