In this guide, we will explain 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 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 :
- 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 DATE function examples and explore how to use the DATE function.
For example:
mysql> SELECT DATE('2014-02-14'); Result: '2014-02-14' mysql> SELECT DATE('2014-02-14 18:20:19'); Result: '2014-02-14' mysql> SELECT DATE('2014-02-15 06:18:01.000001'); Result: '2014-02-15' mysql> SELECT DATE('The date is 2014-02-14'); Result: NULL mysql> SELECT DATE(NULL); Result: NULL
Next Topic : Click Here
Pingback: MySQL: CURTIME Function | Adglob Infosystem Pvt Ltd