Get the difference between 2 dates in JavaScript

function fnvalidation()
{
      var LeaveStartDate = document.getElementById("LeaveStartDate").value;
      var LeaveEndDate = document.getElementById("LeaveEndDate").value;         
      var date1 = new Date(LeaveStartDate);
      var date2 = new Date(LeaveEndDate);
      var timeDiff = Math.abs(date2.getTime() - date1.getTime());
      var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
      alert(diffDays);
      document.getElementById("LeaveDays").value = diffDays;
}

No comments:

Post a Comment