YEARWEEK
Syntax
YEARWEEK(date[,mode])
Description
Returns the year and the week number of a date value.
The mode parameter specifies the logic for calculating the week number, and its values and meanings are described in the table below.
| Value | First day of the week | Range | Meaning |
|---|---|---|---|
| 0 | Sunday | 0~53 | The week starting with the first Sunday is considered the first week of the year. |
| 1 | Monday | 0~53 | The week containing four or more days is considered the first week of the year. |
| 2 | Sunday | 1~53 | The week starting with the first Sunday is considered the first week of the year. |
| 3 | Monday | 1~53 | The week containing four or more days is considered the first week of the year. |
| 4 | Sunday | 0~53 | The week containing four or more days is considered the first week of the year. |
| 5 | Monday | 0~53 | The week starting with the first Monday is considered the first week of the year. |
| 6 | Sunday | 1~53 | The week containing four or more days is considered the first week of the year. |
| 7 | Monday | 1~53 | The week starting with the first Monday is considered the first week of the year. |
info
If the specified date is the first day of the year, this function may return the last week of the previous year.
Examples
SELECT YEARWEEK('2021-01-01');
+------------------------+
| YEARWEEK('2021-01-01') |
+------------------------+
| 202052 |
+------------------------+
1 row in set (0.001 sec)