YEARWEEK(): Year & Week from input date

SELECT YEARWEEK('2023-01-02'); #202301
SELECT YEARWEEK('2023-12-31'); #202353
SELECT YEARWEEK('2024-01-01'); #202353
Syntax
YEARWEEK(date,[mode])
Example
SELECT YEARWEEK('2016-09-23')
Output is 201638
For a invalid date we will get Null as output
SELECT YEAR('2010-02-31')
Output is NULL
DEMO: Select date from Calendar to execute YEARWEEK()

Understanding Mode (Optional Parameter , value 0 to 7)

The week can start on Sunday or Monday,
To understand uses of MODE, read WEEK() function
If mode is not given, then it is considered as 0. The default_week_format of the MySQL system variables is not considered in YEARWEEK() function like WEEK() function. This is the main difference while using MODE between WEEK() function and YEARWEEK() function.

2012-01-01 change the First Day of Week to Monday
2018-01-01 select Sunday as First Day of Week
SQL Date References WEEK() : Week number of year ( 0 to 53 ) WEEKDAY() : 0 for Monday .. 6 for Sunday
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer