Chris Peterson tweeted a good reminder this morning that the subtle difference between
yyyy in the Java date format can lead to unexpected date bugs in your APEX code around this time of year.
For most of the year, the output of
Datetime.format('MM/dd/yyyy') will appear to be interchangeable and all your tests will seem to pass.
These two calendars will appear to align throughout the year and the difference in their outputs will only be noticeable a few days before and/or a few days after the end of a year.
For example, today is December 31, 2020 according to the Gregorian calendar, but if using the
MM/dd/YYYY date format, the output will be
Try it for yourself...
Datetime calendarDay = Datetime.newInstance(2020,12,31); System.debug('Gregorian Calendar Date: ' + calendarDay.format('MM/dd/yyyy')); System.debug('ISO Weeks Calendar Year Format: ' + calendarDay.format('MM/dd/YYYY'));