Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Year_ISO function does not work for end of certain years #12

Open
majkrebs opened this issue Apr 24, 2020 · 0 comments
Open

Year_ISO function does not work for end of certain years #12

majkrebs opened this issue Apr 24, 2020 · 0 comments

Comments

@majkrebs
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant