This function returns the week number for date. The two-argument form of WEEK() enables you to specify whether the week starts on Sunday or Monday and whether the return value should be in the range from 0 to 53 or from 1 to 53. If the mode argument is omitted, the value of the default_week_format system variable is used. See Section 7.1.8, “Server System Variables”. For a NULL date value, the function returns NULL.
SELECT WEEK('2008-02-20');
7
SELECT WEEK('2008-02-20',0);
7
SELECT WEEK('2008-02-20',1);
8
SELECT WEEK('2008-12-31',1);
53
The following table describes how the mode argument works.
SELECT WEEK('2008-02-20');
7
SELECT WEEK('2008-02-20',0);
7
SELECT WEEK('2008-02-20',1);
8
SELECT WEEK('2008-12-31',1);
53
For mode values with a meaning of “with 4 or more days this year,” weeks are numbered according to ISO 8601:1988:
SELECT YEAR('2000-01-01'), WEEK('2000-01-01',0);
2000, 0
If the week containing January 1 has 4 or more days in the new year, it is week 1.
SELECT WEEK('2000-01-01',2);
52
Otherwise, it is the last week of the previous year, and the next week is week 1.
SELECT YEARWEEK('2000-01-01');
199952
SELECT MID(YEARWEEK('2000-01-01'),5,2);
'52'