How MySQL behaves when we use INTERVAL of time unit with CURDATE() function?


As we know that CURDATE() only returns the date unit so it would be ambiguous to use INTERVAL of time unit with CURDATE(). MySQL always represents current date with ‘00:00:00’ time hence when we use INTERVAL of time unit with CURDATE() then such kind of time arithmetic would take this time into consideration. Following examples 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)

Updated on: 28-Jan-2020

59 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements