Syntax
YEARWEEK(date[,mode])
Purpose
Returns the year and the week of the year for a date value.
The mode parameter specifies the logic for calculating the week number, and its value and meaning are shown in the table below.
| Value | First day of the week | Range | Description |
|---|---|---|---|
| 0 | Sunday | 0~53 | The first week of the year is the one that contains the first Sunday. |
| 1 | Monday | 0~53 | The first week of the year is the one that contains at least four days. |
| 2 | Sunday | 1~53 | The first week of the year is the one that contains the first Sunday. |
| 3 | Monday | 1~53 | The first week of the year is the one that contains at least four days. |
| 4 | Sunday | 0~53 | The first week of the year is the one that contains at least four days. |
| 5 | Monday | 0~53 | The first week of the year is the one that contains the first Monday. |
| 6 | Sunday | 1~53 | The first week of the year is the one that contains at least four days. |
| 7 | Monday | 1~53 | The first week of the year is the one that contains the first Monday. |
Note
If the specified date is the first day of the year, this 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
