<-- Back

FormatDateTime(..., 'w') returns unexpected week numbers around year change

Issue

The formatDateTime(date, 'w') function returns unexpected week numbers around the change of the year. Dates at both the end and beginning of a year can be assigned to week fifty-three instead of week one.

For example, both formatDateTime(2025-12-29, 'w') and formatDateTime(2026-01-01, 'w') return fifty-three of 2025, although it is expected to be week one of 2026.

Environment

Studio Pro (all versions)

Cause

The week number returned by formatDateTime(date, 'w') is determined by the application language and Date and Time runtime settings. Mendix relies on Java date formatting, where the week in year calculation is locale-dependent.

When the selected language does not follow ISO 8601 week numbering, dates around the start or end of a year can be assigned to week fifty-three instead of week one. Changing the runtime settings or language to one that aligns with ISO 8601 results in different week number calculations.

For example:

  • The en_US (English, United States) locale does not follow the ISO 8601 standard for week numbering.
  • However, the en_GB (English, United Kingdom) locale does align with the ISO 8601 standard.

Solution / Workaround

To ensure ISO 8601–compliant week numbering when using formatDateTime(date, 'w'), adjust the application default language and runtime settings so that they align with ISO 8601 behavior. 

Internal information related

  • 266615, 261893
  • RUN-4219
  • C3T260XGA/p1724343965920349, C3T260XGA/p1760425734340249

Additional information

Other documentation: Week of year and Week year

Have more questions? Submit a request

0 Comments

Article is closed for comments.

To provide feedback, please open a ticket here. Don't forget to include the article's URL along with the feedback you would like to provide.