MySQL 8.1
WEEK(date[, mode])- [ ]optional part
- date
- Date or datetimeDATE
- mode
- Week numbering mode; taken from the default_week_format variable by default, usually 0INTOptional01234567
Return value
An integer from 0 to 53 or from 1 to 53 depending on mode; NULL for an incomplete date and for an unrecognized value
Examples
Week number by default
MySQL 8.1
SELECT WEEK('2022-06-16');January 1 in different modes
MySQL 8.1
SELECT WEEK('2022-01-01') AS mode_0,
WEEK('2022-01-01', 3) AS mode_3;Details
Days before the first week of the year get number 0 in modes 0, 1, 4 and 5, and the number of the last week of the previous year in modes 2, 3, 6 and 7: WEEK('2022-01-01', 0) returns 0, and WEEK('2022-01-01', 2) returns 52.
It also works the other way: in modes 3 and 6, the last days of December can fall into the first week of the next year: WEEK('2024-12-30', 3) returns 1. To see the year of the week too, use YEARWEEK.