Google Sheets how-to

NYSE trading days in Google Sheets

NETWORKDAYS needs a holiday list you keep up to date, and IMPORTDATA can't read JSON. Two small Apps Script functions give you =TRADING_DAYS("XNYS", A2, B2) and =MARKET_HOLIDAYS("XNYS", 2027) straight from the exchange calendar.

1. Paste the script

In your sheet: Extensions → Apps Script, replace the contents with this, and save.

/**
 * Trading days between two dates (start inclusive, end exclusive).
 * =TRADING_DAYS("XNYS", A2, B2)
 * @customfunction
 */
function TRADING_DAYS(calendar, from, to) {
  const d = (x) => Utilities.formatDate(new Date(x), SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "yyyy-MM-dd");
  const url = "https://settledate.dev/v1/calendars/" + calendar +
    "/trading-days-between?from=" + d(from) + "&to=" + d(to);
  return settledate_(url).business_days;
}

/**
 * Market holidays for a year as a two-column table (date, name).
 * =MARKET_HOLIDAYS("XNYS", 2027)
 * @customfunction
 */
function MARKET_HOLIDAYS(calendar, year) {
  const r = settledate_("https://settledate.dev/v1/calendars/" + calendar + "/holidays?year=" + year);
  return [["Date", "Holiday"]].concat(r.holidays.map((h) => [h.date, h.name]));
}

function settledate_(url) {
  const cache = CacheService.getScriptCache();
  const hit = cache.get(url);
  if (hit) return JSON.parse(hit);
  const key = PropertiesService.getScriptProperties().getProperty("SETTLEDATE_KEY");
  const res = UrlFetchApp.fetch(url, { headers: key ? { "X-API-Key": key } : {}, muteHttpExceptions: true });
  const body = JSON.parse(res.getContentText());
  if (res.getResponseCode() !== 200) throw new Error(body.error.message);
  cache.put(url, res.getContentText(), 21600); // 6 hours
  return body;
}

2. Use it in a cell

FormulaResult
=TRADING_DAYS("XNYS", DATE(2026,11,1), DATE(2026,12,1))20
=TRADING_DAYS("XNYS", DATE(2026,1,1), DATE(2027,1,1))251
=MARKET_HOLIDAYS("XNYS", 2027)Spills a Date / Holiday table: New Year's Day 2027-01-01 … Christmas 2027-12-24 (10 rows)

Results from running the same functions against the live API. The first call asks you to authorize the script to reach settledate.dev. Answers are cached for 6 hours.

3. Add your free key (recommended)

Apps Script calls come from Google's servers, which many scripts share, so the keyless hourly limit can run out on a busy day. Get a free key, then in Apps Script open Project Settings → Script properties and add SETTLEDATE_KEY with your key. The script sends it automatically.

Other calendars: XNAS (Nasdaq), XLON, XETR, XTKS, us-fed (Fed/bank holidays) and any country code such as US or GB-ENG.

That ran without a key. Keyless access covers NYSE, Nasdaq, London, Xetra, Tokyo, the Fed, TARGET2, UK payments and every country calendar, 60 calls an hour per IP. For scripts, notebooks and schedules, a free key gives 5,000 calls a month (no card). Paid plans add the other 24 exchanges.

Get a free key Docs

Questions

Can NETWORKDAYS skip stock market holidays?

Only with a holiday range you keep up to date yourself. TRADING_DAYS counts against the exchange calendar directly, so you don't need NETWORKDAYS or a holiday list.

Why not IMPORTDATA or IMPORTXML?

IMPORTDATA reads CSV and IMPORTXML reads XML/HTML; the calendar API returns JSON, so a short Apps Script function is the reliable way.

Is the end date counted?

No. TRADING_DAYS counts from the start date (inclusive) to the end date (exclusive), like the API's trading-days-between.

Related: NYSE holidays 2026 · Business days calculator · API docs