0

This question: Get difference between 2 dates in javascript? proposed the following way to calculate the difference between two dates:

var _MS_PER_DAY = 1000 * 60 * 60 * 24;

// a and b are javascript Date objects
function dateDiffInDays(a, b) {
  // Discard the time and time-zone information.
  var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
  var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());

  return Math.floor((utc2 - utc1) / _MS_PER_DAY);
}

That's correct for some purposes, but not all purposes. Specifically, with day light savings time you could have a 24-hour span that does not pass midnight, which does not count as a full day for medical billing purposes, for example. How do I calculate specifically the number of midnights that occur between two dates in javascript?

Community
  • 1
  • 1
Matthew
  • 4,149
  • 2
  • 26
  • 53
  • Does this post (http://stackoverflow.com/questions/542938/how-do-i-get-the-number-of-days-between-two-dates-in-javascript) answer your question ? – merours Nov 03 '14 at 14:40
  • If you read the comments on the accepted answer, it actually discusses your daylight savings time issue. – Mark Nov 03 '14 at 16:37

0 Answers0