What happens if the output of MySQL TIMEDIFF() function surpass the range value of TIME field?


As we know that the range of TIME field in MySQL is ‘-838:59:59’ to ‘838:59:59’. Now, if TIMEDIFF() function’s output surpasses this range then MySQL will return either ‘-838:59:59’ or ‘838:59:59’ depends upon the values of the argument.

Example

mysql> Select TIMEDIFF('2017-09-01 03:05:45','2017-10-22 03:05:45')AS 'Out of Range TIME Difference';
+------------------------------+
| Out of Range TIME Difference |
+------------------------------+
| -838:59:59                   |
+------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> Select TIMEDIFF('2017-10-22 04:05:45','2017-09-01 03:05:45')AS 'Out of Range TIME Difference';
+------------------------------+
| Out of Range TIME Difference |
+------------------------------+
| 838:59:59                    |
+------------------------------+
1 row in set, 1 warning (0.01 sec)

The queries above shows that in case the total difference is out of range, MySQL returns either maximum or minimum limit values of the range of TIME field.

Updated on: 30-Jul-2019

89 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements