众所周知,CURDATE()
仅返回日期单位,因此将时间单位的INTERVAL与一起使用会很不明确CURDATE()
。MySQL总是用'00:00:00'时间表示当前日期,因此当我们使用时间单位的INTERVAL时,CURDATE()
这种时间算法将考虑这个时间。以下示例将对其进行澄清-
mysql> Select CURDATE() + INTERVAL 0 hour; +-----------------------------+ | curdate() + Interval 0 hour | +-----------------------------+ | 2017-10-28 00:00:00 | +-----------------------------+ 1 row in set (0.00 sec) mysql> select CURDATE() + INTERVAL 1 hour; +-----------------------------+ | curdate() + Interval 1 hour | +-----------------------------+ | 2017-10-28 01:00:00 | +-----------------------------+ 1 row in set (0.00 sec) mysql> Select CURDATE() + INTERVAL 2 hour; +-----------------------------+ | CURDATE() + INTERVAL 2 hour | +-----------------------------+ | 2017-10-28 02:00:00 | +-----------------------------+ 1 row in set (0.00 sec)