SQL Get “ISO Year” for ISO Week

后端 未结 4 2079
悲&欢浪女
悲&欢浪女 2021-01-05 04:34

I need to calculate the year a week is assigned to. For example the 29th december of 2003 was assigned to week one of year 2004 (this is only for europe, I think). You can t

4条回答
  •  轮回少年
    2021-01-05 05:04

    This solution does not return the correct value for the date '1-1-2027'.

    The following will return the correct value with all dates i tested (and i tested quite a few).

    SELECT YEAR(DATEADD(day, 26 - DATEPART(isoww, '2012-01-01'), '2012-01-01'))
    

    As taken from: https://capens.net/content/sql-year-iso-week

提交回复
热议问题