SelectCURDATE()+INTERVAL0hour;+--------------------------------+|curdate()+ Interval0hour|+----------"/> SelectCURDATE()+INTERVAL0hour;+--------------------------------+|curdate()+ Interval0hour|+----------">
As we all know, CURDATE() only returns date units, so using INTERVAL of time units with CURDATE() creates ambiguity. MySQL always represents the current date in terms of "00:00:00" time, so when we use INTERVAL of time units with CURDATE(), this time arithmetic takes this time into account. The following example will clarify it -
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)
The above is the detailed content of How does MySQL behave when we use INTERVAL of time unit in CURDATE() function?. For more information, please follow other related articles on the PHP Chinese website!