MySQL DATE() Function

MySQL DATE() function; In this tutorial, i am going to show you how to use MySQL date() functions with the help of examples.

And as well as, i will take some example to fetch data from msyql database using mysql date() with queries.

MySQL DATE() function

MySQL DATE() takes the DATE part out from a datetime expression.

Syntax of MySQL DATE() function

DATE(expression);

Where expression is required parameter in DATE(exp). A valid date/datetime value.

Example 1 – MySQL DATE() function

MySQL query statement

SELECT DATE('2019-08-10') as date;

Output1:

 +---------------+
 | date          |
 +---------------+
 | 2019-08-10    | 
 +---------------+

Example 2 – MySQL DATE() function

In the given below MySQL query statement will extract the DATE portion from the specified datetime 2018-08-10 12:50:30.

SELECT DATE("2018-08-10 12:50:30");  

Output2:

 +---------------+
 | date          |
 +---------------+
 | 2018-08-10    | 
 +---------------+

Example 3 – MySQL DATE() function

I will take a example of SELECT query with DATE() function. In the below example we are selecting a data from users table that column name created_at.

SELECT DATE(created_at) as date FROM users;

Output3:

 +---------------+
 | date          |
 +---------------+
 | 1996-07-04    | 
 +---------------+
 +---------------+
 | 1996-07-05    | 
 +---------------+
 +---------------+
 | 1996-07-08    | 
 +---------------+
 +---------------+
 | 1996-07-09    | 
 +---------------+
 +---------------+
 | 1996-07-10    | 
 +---------------+
 +---------------+
 |1996-07-11     | 
 +---------------+

Example 4 – MySQL DATE() function

I will take a example of SELECT statement & NOW() function with DATE() function. It will get only date part of a DATETIME value.

SELECT DATE(NOW());
 +-------------+
 | DATE(NOW()) |
 +-------------+
 | 2019-09-20  |
 +-------------+

Conclusion

In this tutorial – we have discussed about DATE() functions with various examples.

Leave a Comment