MariaDB DAYOFMONTH() Function

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

DAY() is a synonym for DAYOFMONTH().

MariaDB DAYOFMONTH() Syntax

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

DAYOFMONTH(expr)

Parameters

expr

Required. A date or datetime expression.

Return value

The MariaDB DAYOFMONTH() 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 DAYOFMONTH() function will return 0.

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

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

MariaDB DAYOFMONTH() Examples

Basic usage

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

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

Output:

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

Zero day

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

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

Output:

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

Other delimiters

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

SELECT
    DAYOFMONTH('2023/01/08'),
    DAYOFMONTH('2023,01!08'),
    DAYOFMONTH('2023#01%08')\G

Output:

DAYOFMONTH('2023/01/08'): 8
DAYOFMONTH('2023,01!08'): 8
DAYOFMONTH('2023#01%08'): 8

Conclusion

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