MySQL DAY() Function

In MySQL, the DAY() function returns a number representing the day of the month in a datetime expression. This function is equivalent to the DAYOFMONTH() function.

DAY() Syntax

Here is the syntax of MySQL DAY() function:

DAY(expr)

Parameters

expr
Required. A date or datetime expression.

Return value

The MySQL DAY() 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 return 0.
  • If the specified expression is not a valid date or datetime, the function will return NULL.
  • If the argument is NULL, the function will return NULL.

DAY() Examples

Here are some examples of the 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
         DAY('2022-02-28'): 28
DAY('2022-02-28 10:10:10'): 28
                DAY(NOW()): 13
         DAY('2022-02-00'): 0
         DAY('2022-02-30'): NULL
         DAY('Not A DATE'): NULL
                 DAY(NULL): NULL