Skip to main content
Version: V1.0.0

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.

ValueFirst day of the weekRangeMeaning
0Sunday0~53The week containing the first Sunday of the year is considered the first week.
1Monday0~53The week containing four or more days of the year is considered the first week.
2Sunday1~53The week containing the first Sunday of the year is considered the first week.
3Monday1~53The week containing four or more days of the year is considered the first week.
4Sunday0~53The week containing four or more days of the year is considered the first week.
5Monday0~53The week containing the first Monday of the year is considered the first week.
6Sunday1~53The week containing four or more days of the year is considered the first week.
7Monday1~53The 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)