Syntax
YEARWEEK(date[,mode])
Purpose
YEARWEEK() returns the year of date and the ordinal number of the week in the year.
The mode argument indicates the logic for calculating the ordinal number of the week. The following table describes the valid values of mode.
| Value | First day of week | Range | Description |
|---|---|---|---|
| 0 | Sunday | 0 to 53 | The first week is the week that has the first Sunday of the year. |
| 1 | Monday | 0 to 53 | The first week is the first week that has four or more days of the year. |
| 2 | Sunday | 1 to 53 | The first week is the week that has the first Sunday of the year. |
| 3 | Monday | 1 to 53 | The first week is the first week that has four or more days of the year. |
| 4 | Sunday | 0 to 53 | The first week is the first week that has four or more days of the year. |
| 5 | Monday | 0 to 53 | The first week is the week that has the first Monday of the year. |
| 6 | Sunday | 1 to 53 | The first week is the first week that has four or more days of the year. |
| 7 | Monday | 1 to 53 | The first week is the week that has the first Monday of the year. |
Note
If the specified date is the first day of a year, the function may return the last week of the previous year.
Examples
obclient> SELECT YEARWEEK('2021-01-01');
+------------------------+
| YEARWEEK('2021-01-01') |
+------------------------+
| 202052 |
+------------------------+
1 row in set