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

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

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.