How to calculate the number of working days between two dates in JavaScript using moment.js. I have a working formula that calculate these days, but the formula does not sat
you can try this(without loop):
function getBusinessDays(endDate, startDate) {
var lastDay = moment(endDate);
var firstDay = moment(startDate);
let calcBusinessDays = 1 + (lastDay.diff(firstDay, 'days') * 5 -
(firstDay.day() - lastDay.day()) * 2) / 7;
if (lastDay.day() == 6) calcBusinessDays--;//SAT
if (firstDay.day() == 0) calcBusinessDays--;//SUN
return calcBusinessDays;
}
Original Source