Mysql Date Function

MySQL: DATE Function

This tutorial explains how to use the MySQL DATE function with syntax and examples.

Description

The MySQL DATE function extracts the date value from a date or datetime expression.

Syntax

The syntax for the DATE function in MySQL is:

DATE( expression )

Parameters or Arguments

expression

The date or datetime value from which the date should be extracted.

Note

  • If expression is not a date or a datetime value, the DATE function will return NULL.
  • See also the CAST function.

Applies To

The DATE function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1.1

Example

Let's look at some MySQL DATE function examples and explore how to use the DATE function in MySQL.

For example:

mysql> SELECT DATE('2014-02-14');
Output: '2014-02-14'

mysql> SELECT DATE('2014-02-14 18:20:19');
Output: '2014-02-14'

mysql> SELECT DATE('2014-02-15 06:18:01.000001');
Output: '2014-02-15'

mysql> SELECT DATE('The date is 2014-02-14');
Output: NULL

mysql> SELECT DATE(NULL);
Output: NULL