Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Not a Bug
-
10.11, 12.0(EOL)
-
None
Description
We can add ints to the result of now() and cast the sums back to datetime types:
MariaDB [test]> select now(), cast(now()+4200 as datetime);
|
+---------------------+------------------------------+
|
| now() | cast(now()+4200 as datetime) |
|
+---------------------+------------------------------+
|
| 2025-02-14 15:12:32 | 2025-02-14 15:54:32 |
|
+---------------------+------------------------------+
|
1 row in set (0.001 sec)
|
As seen above, we add 4200 to now() and we get a time 42 minutes later.
However, if we add a large enough value such that the result would cross into the next hour, as seen below, we get a NULL when casting instead:
MariaDB [test]> select cast(now()+5200 as datetime);
|
+------------------------------+
|
| cast(now()+5200 as datetime) |
|
+------------------------------+
|
| NULL |
|
+------------------------------+
|
1 row in set, 1 warning (0.001 sec)
|