Home »
MySQL »
MySQL date/time Functions
MySQL DATE() Function
MySQL | DATE() Function: Learn about the DATE() function, how it works, its usages, syntax, and examples.
Submitted by Apurva Mathur, on September 27, 2022
DATE() Function
A table contains different types of data and to fetch some particular data built-in functions help us to extract the data from the table. The DATE() function aid us by fetching out the date part of the date from the table.
DATE() Syntax
SELECT DATE (expression);
This DATE() function always follows the YYYY:DD:MM format, it is important to write your date in this format.
DATE() Parameter(s)
- expression: expression in the form of date/time which is to be fetched.
DATE() Return Value
It will return the date and if there is no date part in the expression then in will return NULL.
MySQL DATE() Function Example 1
As you can see it takes the date in the format given above, and if we will try to change the format then this will show you the NULL value as a result.
MySQL DATE() Function Example 2
Now suppose I have a table named date_of_birth and inside this table, I have the following columns;
As you can see in the date_of_birth column it contains date and time both, but if I only want to fetch the date then in such case I can use the date() function, and for that, we can write,
SELECT name, DATE(date_of_birth) AS dob FROM date_of_birth;
As you can see the result, that only the date part is extracted and rest is ignored.