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>