YEARWEEK( )

This MySQL function returns the year coupled with the number of the week into the year: yyyyww. By default, the first day of the week is Sunday and the basis of the calculation. This MySQL function is somewhat synonymous with WEEK( ).

Syntax

YEARWEEK(date[, value])

Explanation

This function returns the year coupled with the number of the week into the year: yyyyww. By default, the first day of the week is Sunday and the basis of the calculation. Optionally, you can set this to Monday as the first day of the week by entering a value of 1 for the second argument. This function is somewhat synonymous with WEEK( ), but with the year appended to the results and the mode of 2 for that function. If you set the second parameter of this function to 1, it becomes similar to WEEK( ) with the mode of 3.

Examples

SELECT YEARWEEK('2008-01-07')
AS 'YearWeek';

+----------+
| YearWeek |
+----------+
|   200801 |
+----------+

This function can be useful in conjunction with the PERIOD_ADD( ) and PERIOD_DIFF( ) functions.