Skip to main content
Version: V1.0.0

YEARWEEK

Syntax

YEARWEEK(date[,mode])

Description

Returns the year and the week number of a date value.

The mode parameter specifies the logic for calculating the week number, and its values and meanings are described in the table below.

ValueFirst day of the weekRangeMeaning
0Sunday0~53The week starting with the first Sunday is considered the first week of the year.
1Monday0~53The week containing four or more days is considered the first week of the year.
2Sunday1~53The week starting with the first Sunday is considered the first week of the year.
3Monday1~53The week containing four or more days is considered the first week of the year.
4Sunday0~53The week containing four or more days is considered the first week of the year.
5Monday0~53The week starting with the first Monday is considered the first week of the year.
6Sunday1~53The week containing four or more days is considered the first week of the year.
7Monday1~53The week starting with the first Monday is considered the first week of the year.
info

If the specified date is the first day of the year, this function may return the last week of the previous year.

Examples

SELECT YEARWEEK('2021-01-01');
+------------------------+
| YEARWEEK('2021-01-01') |
+------------------------+
| 202052 |
+------------------------+
1 row in set (0.001 sec)