GAS AI BuilderApps Script Assistant Sign in

=HARI_KERJA_LIBUR(start; end; holidays) – working days with a holiday tab

Apps Script recipes › Sheet formulas

Counts working days between two dates, skipping the holidays listed in a range; =HARI_KERJA_LIBUR(B2; C2; Libur!A:A; 6) counts Saturdays as work days.

Use it in a Google Sheet

After saving the code in a script bound to the spreadsheet, type =HARI_KERJA_LIBUR(A2) in a cell. It works on one cell or a range.

File Code.gs

/**
 * Working days between two dates, both counted.
 * @param {Date} start First day.
 * @param {Date} end Last day.
 * @param {Array} [holidays] A range of holiday dates (a second column with 0.5 = half day).
 * @param {number} [daysPerWeek] 5 (Mon–Fri, default) or 6 (Mon–Sat).
 * @return The number of working days.
 * @customfunction
 */
function HARI_KERJA_LIBUR(start, end, holidays, daysPerWeek) {
  if (!(start instanceof Date) || !(end instanceof Date)) return '';
  const key = d => `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
  const off = new Map();
  (Array.isArray(holidays) ? holidays : []).forEach(row => {
    if (row[0] instanceof Date) off.set(key(row[0]), Number(row[1]) === 0.5 ? 0.5 : 1);
  });
  const sixDays = Number(daysPerWeek) === 6;
  let days = 0;
  for (const d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
    const wd = d.getDay();
    if (wd === 0 || (wd === 6 && !sixDays)) continue;
    days += 1 - (off.get(key(d)) || 0);
  }
  return days;
}

Good to know

Let the AI put it in your appGAS AI Builder knows every recipe here. Describe your app and it uses this code where it fits, in a Google Apps Script project in your own Drive.

Use it in a project

More in Sheet formulas

=EMAIL_VALID(text) – check email addressesTRUE when the text looks like an email address; catches spaces, missing @ and common typos like gmial.com.=EMAIL_VALID()=JSON_GET(json; path) – read a value from JSON in a cell=JSON_GET(A2; "customer.name") or "items.0.price" pulls one value out of JSON stored in a cell.=JSON_GET()=NOMOR_HP(phone) – one format for phone numbers"0812-3456-7890" and "+62 812 3456 7890" both become 6281234567890, the form WhatsApp links need.=NOMOR_HP()=RUPIAH(amount) – "Rp 1.250.000" as textFormats a number as rupiah text with dots between thousands, for labels, emails and documents made from the Sheet.=RUPIAH()=SLUG(text) – short ids from names"Kopi Susu Gula Aren (Large)" becomes "kopi-susu-gula-aren-large", for codes, file names and links.=SLUG()=TANGGAL_INDO(date) – "Selasa, 3 November 2026"Writes a date with Indonesian day and month names; =TANGGAL_INDO(A2; FALSE) leaves out the day name.=TANGGAL_INDO()