Skip to content

YEARWEEK

  • date: This is a required parameter that determines the input, which should be a date or datetime value from which the function extracts the year and week. It can also accept a string that can be interpreted as a date.
  • mode: This is an optional parameter that allows control over the way the year and week values are calculated. If omitted, it defaults to 0. This parameter can accept values from 0 to 7, where each number corresponds to a specific behaviour in terms of how the week, year start and end date is calculated and how the week numbers are assigned within the year. For example, when mode is 1, it ensures the week starts on Monday and week 1 is returned for the first week that contains 4 or more days. For other mode values, the behaviour varies similarly.
SELECT YEARWEEK('2022-03-29');
202213

The YEARWEEK function in the example returns the year and week number for the date ‘2022-03-29’. The output 202213 indicates the year 2022 and the 13th week of that year.