Function Reference

DAYOFYEAR

PostgreSQL equivalent:

Returns the day number within the year of a date.

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');
DAYOFYEAR('2024-12-31')
366

Day of the year for birthdays

MySQL 8.1
SELECT member_name,
	DAYOFYEAR(birthday) AS day_of_year
FROM FamilyMembers;
member_nameday_of_year
Headley Quincey134
Flavia Quincey47
Andie Quincey156
Lela Quincey158
Annie Quincey101
Ernest Forrest254
Constance Forrest250
Wednesday Addams13

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.

See also