Name

DATE()

Synopsis

DATE(expression)

This function returns the date from a given string, value, or expression that is submitted in a date or datetime format. This function is available as of version 4.1.1 of MySQL. Here is an example:

SELECT appointment, DATE(appointment)
FROM appointments
WHERE client_id = '8639' LIMIT 1;

+---------------------+-------------------+
| appointment         | DATE(appointment) |
+---------------------+-------------------+
| 2008-01-11 14:11:43 | 2008-01-11        |
+---------------------+-------------------+

In this SQL statement, the value of the appointment column, which is a DATETIME type column, is shown first. The second field is the date extracted by the function from the same column and row.

Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.