mysql - How to set negative time difference value to zero -


if time difference result negative how set zero

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

| -06:59:33 |

try this:

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')) diff; 

Comments