如何将负时差值设置为零

时间:2016-01-29 08:04:44

标签: mysql

如果时差结果为负,我该如何设置为零

select TIMEDIFF('2016-01-29 12:28:18','2016-01-29 19:27:51') as diff;

| -06:59:33 |

1 个答案:

答案 0 :(得分:0)

试试这个:

select if((time_to_sec(TIMEDIFF('2016-01-29 12:28:18','2016-01-29 19:27:51'))/3600) < 0,0,TIMEDIFF('2016-01-29 12:28:18','2016-01-29 19:27:51')) as diff;