MySQL 8.1
DAYOFYEAR(date)Parameters
- dateDATE
- Date or datetime
Return value
An integer from 1 to 366; NULL for an incomplete date (2022-00-00) and for an unrecognized value
Examples
Last day of a leap year
MySQL 8.1
SELECT DAYOFYEAR('2024-12-31');Day of the year for birthdays
MySQL 8.1
SELECT member_name,
DAYOFYEAR(birthday) AS day_of_year
FROM FamilyMembers;Details
The reverse conversion — a date from a year and a day number — is done by MAKEDATE. Because of leap years, the same day number can fall on different dates in different years: day 60 is March 1 or February 29.