在mysql中比较日期时间的现象?

时间:2016-07-22 12:20:31

标签: mysql datetime

我在mysql中比较datetime时发现了一种现象,见下文

select create_time, create_time > date(create_time)+3 from datetime_test;
 +---------------------+-----------------------------------+
 | create_time         | create_time > date(create_time)+3 |
 +---------------------+-----------------------------------+
 | 2016-07-22 20:08:31 |                                 1 |
 +---------------------+-----------------------------------+

为什么在create_time之后date(create_time)+3

select create_time, create_time > date(now())+3 from datetime_test;
+---------------------+-----------------------------+
| create_time         | create_time > date(now())+3 |
+---------------------+-----------------------------+
| 2016-07-22 20:08:31 |                           0 |
+---------------------+-----------------------------+

但将create_time更改为now()时可以。

select create_time, create_time>current_date+3 from datetime_test;
+---------------------+----------------------------+
| create_time         | create_time>current_date+3 |
+---------------------+----------------------------+
| 2016-07-22 20:08:31 |                          0 |
+---------------------+----------------------------+

并将create_time更改为current_date它也可以。

select date(create_time)+3, date(now())+3, current_date+3 from datetime_test;
+---------------------+---------------+----------------+
| date(create_time)+3 | date(now())+3 | current_date+3 |
+---------------------+---------------+----------------+
|            20160725 |      20160725 |       20160725 |
+---------------------+---------------+----------------+

但它们都是一样的。

select create_time, create_time>'20160725' from datetime_test;
+---------------------+------------------------+
| create_time         | create_time>'20160725' |
+---------------------+------------------------+
| 2016-07-22 20:08:31 |                      0 |
+---------------------+------------------------+

并直接使用20160725它还可以。

那么第一个sql有什么问题? date(create_time)+3和其他人之间有什么区别?

0 个答案:

没有答案