Calculate working days between two dates in Javascript excepts holidays (ok)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script type="text/javascript">
    var startDate = new Date('12/26/2021');
    var endDate = new Date('12/27/2021');
    var numOfDates = getBusinessDatesCount(startDate, endDate);
    function getBusinessDatesCount(startDate, endDate) {
      let count = 0;
      const curDate = new Date(startDate.getTime());
      while (curDate <= endDate) {
        const dayOfWeek = curDate.getDay();
        if (dayOfWeek !== 0 && dayOfWeek !== 6) count++;
        curDate.setDate(curDate.getDate() + 1);
      }
      console.log(count);
      return count;
    }
  </script>
</body>
</html>

Last updated