Syntax
WEEK(date[,mode])
Purpose
WEEK() returns the ordinal number of the week in the year of date.
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 WEEK('2021-01-01',0);
+----------------------+
| WEEK('2021-01-01',0) |
+----------------------+
| 0 |
+----------------------+
1 row in set