When using System.formatDate in a workflow script to format dates at the end of December, the output year may appear as the following year (e.g., December 29, 2025, is formatted as "2026-12-29").
This typically occurs during the last week of the calendar year.
This behavior is by design and is caused by the use of the Week-based Year (YYYY) format pattern instead of the Calendar Year (yyyy) pattern.
Difference between yyyy and YYYY
yyyy (Calendar Year): Represents the standard Gregorian calendar year. December 29, 2025, remains 2025.
YYYY (Week-based Year): Follows the ISO 8601 week date standard. In this system, if a week spans two years, the entire week is assigned to the year that contains the majority of its days (4 or more).
In late 2025, because the majority of that specific week falls into January 2026, the YYYY token pulls the date forward into the 2026 week-year.
To ensure the date matches the standard calendar year, update your JavaScript code to use lowercase yyyy.
Incorrect (Week-based):
var result = System.formatDate(dateObj, "YYYY-MM-dd"); // Output on Dec 29: 2026-12-29
Correct (Calendar Year):
var result = System.formatDate(dateObj, "yyyy-MM-dd"); // Output on Dec 29: 2025-12-29
Related Information: