Error guides

Utilities.formatDate with YYYY shows the wrong year

var d = new Date(2025, 11, 29);                       // Dec 29, 2025
Utilities.formatDate(d, 'America/New_York', 'YYYY-MM-DD');  // "2026-12-363"  ← wrong
Utilities.formatDate(d, 'America/New_York', 'yyyy-MM-dd');  // "2025-12-29"

Why it happens

Utilities.formatDate uses Java SimpleDateFormat letters, not the YYYY-MM-DD you'd write in a spreadsheet:

LetterMeansYou probably wanted
YYYYweek-based year (flips early in late December)yyyy
DDday of year (1–366)dd
mmminutesMM (month)
hh1–12 hourHH (0–23)

The bug hides for most of the year, then breaks file names and reports in the last days of December. It shows up a lot in Rhino-era scripts — fix it while you migrate.

Time zones

Pass Session.getScriptTimeZone() (not the removed Session.getTimeZone()), or the spreadsheet's getSpreadsheetTimeZone() when formatting dates read from cells.

var ss = SpreadsheetApp.getActive();
Utilities.formatDate(date, ss.getSpreadsheetTimeZone(), 'yyyy-MM-dd');

How V8Shift handles it

Patterns containing YYYY/DD are rewritten to yyyy/dd (marked for review) and Session.getTimeZone() becomes Session.getScriptTimeZone().

Have a whole project to migrate? Paste your .gs or upload a zip for a free V8 compatibility report — every occurrence of this pattern with file and line, plus an auto-rewritten project.
Related errors