Year_ISO function does not work for end of certain years
majkrebs opened this issue · 0 comments
majkrebs commented
The YEAR_ISO(ADATE DATE) function handles the first few days of the year but it does not handle the end of the year correctly. For example:
2019-12-30 is ISO year 2020 but returns 2019. My suggestion is:
CASE WHEN DAYOFYEAR(ADATE) <= 7 AND WEEK_ISO(ADATE) >= 52
THEN YEAR(ADATE) - 1
when dayofYear(adate) >= 363 and week_iso(adate) = 1
then year(adate) + 1
ELSE YEAR(ADATE)
end
363 is the earliest day of the year that can be the next year.