How MySQL evaluates if I store date along with time value in a column having DATE data type?


As we know that 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. But still, if we store date along with time value in a column having DATE data type then MySQL will show a warning and store only the date value in that column. Following example will exhibit it −

Example

mysql> Create table date_time_test(date DATE);
Query OK, 0 rows affected (0.44 sec)

mysql> Insert into date_time_test(date) values(‘2017-09-09 09:34:21’);
Query OK, 1 row affected, 1 warning (0.03 sec)

mysql> Select * from date_time_test;
+------------+
| date |
+------------+
| 2017-09-09 |
+------------+
1 row in set (0.00 sec)

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

Updated on: 20-Jun-2020

60 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements