MySQL YEARWEEK is one of the Date Functions, which returns the Year and Week of the given date. The mode argument in this YearWeek function works exactly the same as the Week() function.
In this article, we show you how to use this YearWeek function to get the calendar year and Week number with an example. The basic syntax of this YEARWEEK method is as shown below:
YEARWEEK(date);
YEARDATE(date, mode);
Here, the Mode is an optional argument. For example, if Mode = 0, then the week starts on Sunday, and the return value is between 0 and 53.
MySQL YEARWEEK function Example
The following examples help you understand the use of this YEARWEEK method. Here, we are returning the calendar Year and week number of different dates. Also, read about the MySQL WEEKOFYEAR function.
SELECT YEARWEEK('2018-05-17');
SELECT YEARWEEK('2018-12-31');
SELECT YEARWEEK('2018-10-19');

Let us see another example of the YEARWEEK Date method. This time, we are using the MySQL Mode argument as the second argument value.
TIP: Please refer to the MySQL YEAR and MySQL WEEK functions from the list of available MySQL Date functions.
SELECT YEARWEEK('2018-12-31', 6);
SELECT YEARWEEK('2018-01-01', 2);
SELECT YEARWEEK('2018-01-01', 7);
