Just like mentioned above you should use 'yyyy' in stead of 'YYYY'.
With yyyy you get the year from the date you are using.
With YYYY you get the year of the week your date is in.
In this case 2018-12-31 is on a Monday, the first week of 2019.
Today I experienced the same issue with formatting the date to a weeknumber.
In this case, the weeknumber needs to be based on a date in order to retrieve a project that is set for that week.
The startdate is February 9th 2019 (or 09-02-2019).
As shown, the formatDateTime does find the correct day of the week (6). However, when the week is retrieved using the same function, week 7 is generated instead of week 6 (which is correct).
The code for the variable WeekString is:
Using uppercase results this in returning a ‘2’, but that is definitely wrong?
Is this a wider known issue? Is there a workaround?