Why we cannot use MySQL DATE data type along with time value?


The default format for MySQL DATE data type is “YYYY-MM-DD” and in this format, there is no possibility to store the time value. Hence, we can say that we cannot use DATE data type along with time value.

As we can see in the following example MySQL returns only date value even on using time along with the date.

mysql> select DATE("2017-09-25 09:34:21");
+-----------------------------------+
| DATE("2017-09-25 09:34:21")       |
+-----------------------------------+
| 2017-09-25                        |
+-----------------------------------+
1 row in set (0.04 sec)

However, in DATETIME and TIMESTAMP date data types we can use the time to date.

Updated on: 28-Jan-2020

78 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements