Skip to main content

WEEK

week​

Description​

Syntax​

INT WEEK(DATE date[, INT mode])

Returns the week number for date.The value of the mode argument defaults to 0. The following table describes how the mode argument works.

ModeFirst day of weekRangeWeek 1 is the first week …
0Sunday0-53with a Sunday in this year
1Monday0-53with 4 or more days this year
2Sunday1-53with a Sunday in this year
3Monday1-53with 4 or more days this year
4Sunday0-53with 4 or more days this year
5Monday0-53with a Monday in this year
6Sunday1-53with 4 or more days this year
7Monday1-53with a Monday in this year

The parameter is Date or Datetime type

example​

Out-of-range modes use their lowest three bits. For example, 8 selects mode 0:

SELECT WEEK('2021-01-01', 8) AS mode_8,
WEEK('2021-01-01', 0) AS mode_0,
WEEK('2021-01-01', 7) AS mode_7;
+--------+--------+--------+
| mode_8 | mode_0 | mode_7 |
+--------+--------+--------+
| 0 | 0 | 52 |
+--------+--------+--------+
mysql> select week('2020-1-1');
+------------------+
| week('2020-1-1') |
+------------------+
| 0 |
+------------------+
mysql> select week('2020-7-1',1);
+---------------------+
| week('2020-7-1', 1) |
+---------------------+
| 27 |
+---------------------+

keywords​

WEEK