Counting business days in Javascript

(@ScottR you are a lifesaver :pray: )

Stepping in here as well, just in case anyone else is curious! I was able to count business days using this code in a JS transformer:

function countBusinessDays(startDate, endDate) {
  var day = moment(startDate);
  var businessDays = 0;

  while (day.isSameOrBefore(endDate,'day')) {
    if (day.day()!=0 && day.day()!=6) businessDays++;
    day.add(1,'d');
  }
  return businessDays;
}

return countBusinessDays({{dateRange1.value.start}}, {{dateRange1.value.end}})

Not sure if this is the best way, but it's certainly one way!

1 Like