MySQL DAYOFMONTH() Function
In MySQL, the DAYOFMONTH()
function returns a number representing the day of the month in a datetime expression. This function is equivalent to the DAYOFMONTH()
function.
DAYOFMONTH()
Syntax
Here is the syntax of MySQL DAYOFMONTH()
function:
DAYOFMONTH(expr)
Parameters
expr
- Required. A date or datetime expression.
Return value
The MySQL DAYOFMONTH()
function returns a number representing the day of the month in a datetime expression, from 1 to 31.
- If the day part of the given date is 0, eg:
'0000-00-00'
and'2008-00-00'
, the function will return0
. - If the specified expression is not a valid date or datetime, the function will return
NULL
. - If the argument is
NULL
, the function will returnNULL
.
DAYOFMONTH()
Examples
Here are some examples of the 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
DAYOFMONTH('2022-02-28'): 28
DAYOFMONTH('2022-02-28 10:10:10'): 28
DAYOFMONTH(NOW()): 13
DAYOFMONTH('2022-02-00'): 0
DAYOFMONTH('2022-02-30'): NULL
DAYOFMONTH('Not A DATE'): NULL
DAYOFMONTH(NULL): NULL