selectDATE("2017-09-2509:34:21");+-------------------------------- ---+|DATE("2017-09-2509:34:21")&n"/> selectDATE("2017-09-2509:34:21");+-------------------------------- ---+|DATE("2017-09-2509:34:21")&n">

Home >Database >Mysql Tutorial >Why can't we use MySQL DATE data type with time values?

Why can't we use MySQL DATE data type with time values?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBforward
2023-08-25 15:57:141354browse

为什么我们不能将 MySQL DATE 数据类型与时间值一起使用?

The default format of the MySQL DATE data type is "YYYY-MM-DD". In this format, time values ​​cannot be stored. Therefore, we can say that we cannot use DATE data type with time values.

As we can see in the example below, MySQL only returns date values ​​even when using time with 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 time to date.

The above is the detailed content of Why can't we use MySQL DATE data type with time values?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete