MySQL YEARWEEK function is a Date Function, which return the Year and Week of the given date. The mode argument in this function works exactly the same as the Week() function
In this article, we will show you, How to use this YearWeek function to get the calendar year and Week number in MySQL with an example.
MySQL YEARWEEK Syntax
The basic syntax of the YearWeek() Function in MySQL is as shown below:
Here, Mode is an optional argument. For example, if Mode = 0 then week starts on Sunday, and return value is between 0 and 53.
MySQL YEARWEEK function Example
The following examples helps you understand the use of this YEARWEEK function. Here, we are returning the calendar Year and week number of different dates.
Let us see another example of the MySQL YEAR WEEK function. This time we are using the Mode argument as the second argument value.
SELECT YEARWEEK('2018-12-31', 6);
SELECT YEARWEEK('2018-01-01', 2);
SELECT YEARWEEK('2018-01-01', 7);
Thank You for Visiting Our Blog