Home  >  Article  >  Database  >  What happens if the output of the MySQL TIMEDIFF() function exceeds the range value of the TIME field?

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

WBOY
WBOYforward
2023-09-22 13:01:02702browse

如果 MySQL TIMEDIFF() 函数的输出超出 TIME 字段的范围值会发生什么?

We know that the range of the TIME field in MySQL is ‘-838:59:59’ to ‘838:59:59’. Now, if the output of the TIMEDIFF() function is outside this range, MySQL will return '-838:59:59' or '838:59:59', depending on the value 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 above query shows that if the total difference exceeds the range, MySQL will return the maximum or minimum limit value of the TIME field range.

The above is the detailed content of What happens if the output of the MySQL TIMEDIFF() function exceeds the range value of the TIME field?. 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