0

Due to daylight saving time in London, I'm not able to get the correct count for weekdays and weekend days. In the below fiddle 26/10/2019 is considering at times as weekday and at times as a weekend. I want to get the output for the below fiddle is "workingDays": 1, "weekendDays": 2

Any suggestions, please?

var startDate = new Date('2019-10-26');
var endDate = new Date('2019-10-28');
var workingDays = number_of_working_days(startDate, endDate);
var weekendDays = number_of_weekend_days(startDate, endDate);
console.log({
  'workingDays': workingDays,
  'weekendDays': weekendDays
})

function number_of_working_days(startDate, endDate) {
  var workingDays = 0;
  for (var i = startDate; i <= endDate; i = i + (60 * 60 * 24)) {
    if (i.getDay() <= 5) {
      workingDays = workingDays + 1;
    }

  }
  return workingDays;
}

function number_of_weekend_days(startDate, endDate) {
  var weekendDays = 0;
  for (var i = startDate; i <= endDate; i = i + (60 * 60 * 24)) {
    if (i.getDay() > 5) {
      weekendDays = weekendDays + 1;
    }
  }
  return weekendDays;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
06011991
  • 797
  • 2
  • 13
  • 39
  • I don't believe you can do it without working in "non-DST" ... and also keep your sanity. Check out this: https://stackoverflow.com/a/45908136/595305 ... for adjusting to/from DST (our BST). – mike rodent Nov 12 '19 at 11:49
  • @mikerodent Sure, I shall check the reference and adjust the dates – 06011991 Nov 12 '19 at 11:52

0 Answers0