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