我在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
和其他人之间有什么区别?