> For the complete documentation index, see [llms.txt](https://javascriptuse.gitbook.io/advanced/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascriptuse.gitbook.io/advanced/calculate-working-days-between-two-dates-in-javascript-excepts-holidays-ok.md).

# 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>
```
