MariaDB DAYOFYEAR() Function

In MariaDB, DAYOFYEAR() is a built-in function that returns a number representing the day of the year for a given date.

MariaDB DAYOFYEAR() Syntax

This is the syntax of the MariaDB DAYOFYEAR() function:

DAYOFYEAR(expr)

Parameters

expr

Required. A date or datetime expression.

If you provide no parameters or the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'DAYOFYEAR'.

Return value

The MariaDB DAYOFYEAR() function returns a number representing the day of the year for a given date, from 1 to 366.

If the specified expression is not a valid date or datetime, the DAYOFYEAR() function will return NULL.

If the argument is NULL, the DAYOFYEAR() function will return NULL.

MariaDB DAYOFYEAR() Examples

This statement shows the basic usage of the MariaDB DAYOFYEAR() function:

SELECT
    DAYOFYEAR('2022-01-01'),
    DAYOFYEAR('2022-01-31'),
    DAYOFYEAR('2022-02-28 10:10:10'),
    DAYOFYEAR('2022-02-00'),
    DAYOFYEAR('2022-02-30'),
    DAYOFYEAR('Not A DATE'),
    DAYOFYEAR(NULL)\G

Output:

         DAYOFYEAR('2022-01-01'): 1
         DAYOFYEAR('2022-01-31'): 31
DAYOFYEAR('2022-02-28 10:10:10'): 59
         DAYOFYEAR('2022-02-00'): NULL
         DAYOFYEAR('2022-02-30'): NULL
         DAYOFYEAR('Not A DATE'): NULL
                 DAYOFYEAR(NULL): NULL

To return the day of the year for today, use any NOW(), CURDATE(), CURRENT_DATE(), or SYSDATE(), for example:

SELECT
    DAYOFYEAR(NOW()),
    DAYOFYEAR(CURDATE()),
    DAYOFYEAR(CURRENT_DATE()),
    DAYOFYEAR(SYSDATE())\G

Output:

         DAYOFYEAR(NOW()): 7
     DAYOFYEAR(CURDATE()): 7
DAYOFYEAR(CURRENT_DATE()): 7
     DAYOFYEAR(SYSDATE()): 7

Note that your results may be different.

Conclusion

In MariaDB, DAYOFYEAR() is a built-in function that returns a number representing the day of the year for a given date.