MySQL Tutorial MySQL Advanced MySQL Database Account Management MySQL References

MySQL DATE() Function



The MySQL DATE() function is used to extract the date value from a date or datetime expression.

Syntax

DATE(expression)

Parameters

expression Required. Specify a valid date or datetime value from which the date should be extracted. Returns NULL if the expression is not a valid date or datetime value.

Return Value

Returns the date value of a given date or datetime expression.

Example 1:

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

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

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

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

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

mysql> SELECT DATE(CURDATE());
Result: '2021-11-16'

mysql> SELECT DATE(NULL);
Result: NULL

mysql> SELECT DATE('Date is 2014-10-25');
Result: NULL

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 date value of records of column OrderTime:

SELECT *, DATE(OrderTime) AS DATE_Value FROM Orders;

This will produce the result as shown below:

OrderQuantityPriceOrderTimeDATE_Value
1001.582017-08-18 10:38:422017-08-18
1201.612018-03-23 07:14:162018-03-23
1251.782018-09-12 05:25:562018-09-12
501.802019-01-16 11:52:052019-01-16
2001.722020-02-06 09:31:342020-02-06

❮ MySQL Functions