SelectCURDATE()+INTERVAL0hour;+--------------------------------+|curdate()+ Interval0hour|+----------"/> SelectCURDATE()+INTERVAL0hour;+--------------------------------+|curdate()+ Interval0hour|+----------">

Home  >  Article  >  Database  >  How does MySQL behave when we use INTERVAL of time unit in CURDATE() function?

How does MySQL behave when we use INTERVAL of time unit in CURDATE() function?

WBOY
WBOYforward
2023-09-11 12:21:101323browse

当我们在 CURDATE() 函数中使用时间单位的 INTERVAL 时,MySQL 会如何表现?

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!

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