Syntax
WEEK(date[,mode])
Purpose
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. The following table describes the values of the mode parameter.
| Value | First day of the week | Range | Description |
|---|---|---|---|
| 0 | Sunday | 0~53 | The week that contains the first Sunday of the year is considered the first week of the year. |
| 1 | Monday | 0~53 | The week that contains four or more days of the year is considered the first week of the year. |
| 2 | Sunday | 1~53 | The week that contains the first Sunday of the year is considered the first week of the year. |
| 3 | Monday | 1~53 | The week that contains four or more days of the year is considered the first week of the year. |
| 4 | Sunday | 0~53 | The week that contains four or more days of the year is considered the first week of the year. |
| 5 | Monday | 0~53 | The week that contains the first Monday of the year is considered the first week of the year. |
| 6 | Sunday | 1~53 | The week that contains four or more days of the year is considered the first week of the year. |
| 7 | Monday | 1~53 | The week that contains the first Monday of the year is considered the first week of the year. |
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 WEEK('2021-01-01',0);
+----------------------+
| WEEK('2021-01-01',0) |
+----------------------+
| 0 |
+----------------------+
1 row in set
