Home »
MySQL »
MySQL date/time Functions
MySQL YEARWEEK() Function
MySQL | YEARWEEK() Function: Learn about the YEARWEEK() function, how it works, its usages, syntax, and examples.
Submitted by Apurva Mathur, on October 13, 2022
YEARWEEK() Function
The YEARWEEK() function is used to get the year and the week number. The range for the week number is 0 to 53.
YEARWEEK() Syntax
SELECT YEARWEEK('date','mode[optional]');
YEARWEEK() Parameter(s)
The function accepts the two parameters, they are -
- date: You have to provide the valid date on which this function will fetch the year and week numbers.
- mode: This parameter is optional. This parameter specified the day on which the week starts.
The following modes are present in this function:
- 0 - First day of week is Sunday
- 1 - First day of week is Monday and the first week of the year has more than 3 days
- 2 - First day of week is Sunday
- 3 - First day of week is Monday and the first week of the year has more than 3 days
- 4 - First day of week is Sunday and the first week of the year has more than 3 days
- 5 - First day of week is Monday
- 6 - First day of week is Sunday and the first week of the year has more than 3 days
- 7 - First day of week is Monday
YEARWEEK() Return Value
This function returns the year and the week number.
MySQL YEARWEEK() Function Example 1
SELECT YEARWEEK('1987-10-11');
Here 1987 is the year and 41 is the week number.
MySQL YEARWEEK() Function Example 2
SELECT YEARWEEK('2020-01-11');
In this example, 2020 is the year and 01 is the week number.