MySQL DATE() Function Examples

MySQL DATE() Function Examples

MySQL DATE() function; In this tutorial, we will discuss about MySQL date() functions with help of examples.

MySQL offers various date and Time functions to work with Dates such as Finding current date, Time, format date, extract date part, time part etc. In our previous tutorial, we have shared a list of MySQL Date functions that are available to work with Date and time.

We will use SELECT statement query with DATE() functions and show the example of SELECT statement with date() function.

MySQL DATE() function

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

Syntax:

DATE(expression);

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

Example First of MySQL DATE() function:

MySQL query statement

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

Output1:

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

Example Second of 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 Third of MySQL DATE() function

Now we 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 fourth of MySQL DATE()

Now we 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.

Recommended MySQL Tutorials

If you have any questions or thoughts to share, use the comment form below to reach us.

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *