This tutorial explains how to use the MySQL YEARWEEK function with syntax and examples.
The MySQL YEARWEEK function returns the year and week for a date value.
The syntax for the YEARWEEK function in MySQL is:
A date or datetime value from which to extract the year and week.
Optional. It is used to specify what day the week starts on. It can be one of the following:
mode | Explanation | Week Value |
---|---|---|
0 | First day of the week is Sunday | 0-53 |
1 | First day of the week is Monday and the first week has more than 3 days | 0-53 |
2 | First day of the week is Sunday | 1-53 |
3 | First day of the week is Monday and the first week has more than 3 days | 1-53 |
4 | First day of the week is Sunday and the first week has more than 3 days | 0-53 |
5 | First day of the week is Monday | 0-53 |
6 | First day of the week is Sunday and the first week has more than 3 days | 1-53 |
7 | First day of the week is Monday | 1-53 |
The YEARWEEK function can be used in the following versions of MySQL:
Let's look at some MySQL YEARWEEK function examples and explore how to use the YEARWEEK function in MySQL.
For example: (Note: Your results may vary from the examples below depending on what your default_week_format system variable is set to.)
This last YEARWEEK example would display the year and week for the current system date (current system date is returned by the CURDATE function).