SQL Tutorial SQL Advanced SQL Database SQL References

MySQL DAY() Function



The MySQL DAY() function returns the day portion of a given date or datetime value. It can be between 1 to 31.

The DAY() function is a synonym for the DAYOFMONTH() function.

Syntax

DAY(datetime)

Parameters

datetime Required. Specify a date or datetime value from which to extract the day.

Return Value

Returns the day part of a given date or datetime value.

Example 1:

The example below shows the usage of DAY() function.

mysql> SELECT DAY('2018-08-18');
Result: 18

mysql> SELECT DAY('2018-08-18 10:38:42');
Result: 18

mysql> SELECT DAY('2018-08-18 10:38:42.000004');
Result: 18

mysql> SELECT DAY('2014-10-25');
Result: 25

mysql> SELECT DAY(CURDATE());
Result: 28

Example 2:

Consider a database table called Orders with the following records:

OrderQuantityPriceOrderTime
1001.582017-08-18 10:38:42
1201.612018-03-23 07:14:16
1251.782018-09-12 05:25:56
501.802019-01-16 11:52:05
2001.722020-02-06 09:31:34

The statement given below can be used to get the day portion of records of column OrderTime:

SELECT *, DAY(OrderTime) AS DAY_Value FROM Orders;

This will produce the result as shown below:

OrderQuantityPriceOrderTimeDAY_Value
1001.582017-08-18 10:38:4218
1201.612018-03-23 07:14:1623
1251.782018-09-12 05:25:5612
501.802019-01-16 11:52:0516
2001.722020-02-06 09:31:346

❮ MySQL Functions