MariaDB DAY() Function

In MariaDB, DAY() is a built-in function that returns the number representing the day of the month in a given datetime expression.

DAY() is a synonym for DAYOFMONTH().

MariaDB DAY() Syntax

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

DAY(expr)

Parameters

expr

Required. A date or datetime expression.

Return value

The MariaDB DAY() function returns the day-of-month number, from 1 to 31, in a datetime expression.

If the day part of the given date is 0, eg: '0000-00-00' or '2008-00-00', the DAY() function will return 0.

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

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

MariaDB DAY() Examples

Basic usage

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

SELECT
    DAY('2022-02-28'),
    DAY('2022-02-28 10:10:10'),
    DAY(NOW()),
    DAY('2022-02-00'),
    DAY('2022-02-30'),
    DAY('Not A DATE'),
    DAY(NULL)\G

Output:

         DAY('2022-02-28'): 28
DAY('2022-02-28 10:10:10'): 28
                DAY(NOW()): 7
         DAY('2022-02-00'): 0
         DAY('2022-02-30'): NULL
         DAY('Not A DATE'): NULL
                 DAY(NULL): NULL

Zero day

This statement shows how the MariaDB DAY() function handles 0000-00-00:

SELECT DAY('0000-00-00');

Output:

+-------------------+
| DAY('0000-00-00') |
+-------------------+
|                 0 |
+-------------------+

Other delimiters

The MariaDB DAY() function allow you to construct dates with various separators:

SELECT
    DAY('2023/01/08'),
    DAY('2023,01!08'),
    DAY('2023#01%08');

Output:

+-------------------+-------------------+-------------------+
| DAY('2023/01/08') | DAY('2023,01!08') | DAY('2023#01%08') |
+-------------------+-------------------+-------------------+
|                 8 |                 8 |                 8 |
+-------------------+-------------------+-------------------+

Conclusion

In MariaDB, DAY() is a built-in function that returns the number representing the day of the month in a given datetime expression.