Home > Database > Mysql Tutorial > 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?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-09-11 12:21:10
forward
1414 people have browsed it

当我们在 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)
Copy after login

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template