What is DAYOFYEAR() in SQL?
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.
Syntax
DAYOFYEAR(date)
Parameter
The DAYOFYEAR() function takes the date as a parameter.
Dates must be in the format YYYY-MM-DD, or else this function returns
NULL.
Return value
The DAYOFYEAR() function returns the day of the year from a date sent as a parameter.
It returns
NULLif the date is invalid.
Example
-- current dateSELECT DAYOFYEAR(NOW());-- invalid monthSELECT DAYOFYEAR('2021-13-12');-- valid month/daySELECT DAYOFYEAR('2021-05-03');-- invalid daySELECT DAYOFYEAR('2021-2-30');