Calculate business days in JavaScript

A dependency-free implementation, and the API call that replaces it when you need real holiday calendars.

Option 1: implement it

Work in UTC to avoid timezone drift around midnight.

function addBusinessDays(iso, n, holidays = new Set()) {
  const d = new Date(iso + "T00:00:00Z");
  const step = Math.sign(n);
  let left = Math.abs(n);
  while (left > 0) {
    d.setUTCDate(d.getUTCDate() + step);
    const dow = d.getUTCDay();
    const key = d.toISOString().slice(0, 10);
    if (dow !== 0 && dow !== 6 && !holidays.has(key)) left--;
  }
  return d.toISOString().slice(0, 10);
}

addBusinessDays("2027-11-24", 2, new Set(["2027-11-25"]));
// "2027-11-29"

This assumes a Saturday-Sunday weekend. Friday-Saturday regions (Saudi Arabia, Egypt) and substitute-holiday rules need additional handling.

Option 2: Dierum API

const r = await fetch(
  "https://dierum.io/v1/add?region=SA&start=2027-01-06&days=2",
  { headers: { "X-Api-Key": KEY } },
);
const { result } = await r.json();   // "2027-01-10"

The SA calendar applies the Friday-Saturday weekend automatically. For date inputs that block non-working days in the browser, see the widget library.

Need this in code? The API answers the same questions over HTTPS with one GET request. Free tier of 100 calls a day, and the playground needs no key at all.