我们知道MySQL中TIME字段的范围是'-838:59:59'到'838:59:59'。现在,如果TIMEDIFF()
函数的输出超过该范围,则MySQL将根据参数的值返回'-838:59:59'或'838:59:59'。
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)
上面的查询显示,如果总差异超出范围,MySQL将返回TIME字段范围的最大或最小限制值。