The DAYOFYEAR()
function returns the day of the year from a date sent as a parameter. There are 365 days in a year.
There are 366 days in a leap year.
Figure 1 shows a visual representation of the DAYOFYEAR()
function.
DAYOFYEAR(date)
The DAYOFYEAR()
function takes the date as a parameter.
Dates must be in the format YYYY-MM-DD, or else this function returns
NULL
.
The DAYOFYEAR()
function returns the day of the year from a date sent as a parameter.
It returns
NULL
if the date is invalid.
-- current dateSELECT DAYOFYEAR(NOW());-- invalid monthSELECT DAYOFYEAR('2021-13-12');-- valid month/daySELECT DAYOFYEAR('2021-05-03');-- invalid daySELECT DAYOFYEAR('2021-2-30');