To calculate date difference between two given dates

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 =