Comparing TIMEDIFF in MySQL

date, mysql, sql

Solution

Try getting the difference in hours and then comparing.

SELECT TimeDiff(TimeOut,TimeIn) 
from table where HOUR(TIMEDIFF(endDate, startDate)) < 50 

Problem

I have these following data: ``` ID TIMEIN TIMEOUT 1 2016-08-24 20:44:00 2016-10-22 19:35:36 2 2016-08-24 20:58:00 2016-08-24 20:59:09 ``` and the following query that I want to use to find all the entries where the timediff is lesser than 50 hours ``` SELECT TimeDiff(TimeOut,TimeIn) from table where TimeDiff(TimeOut,TimeIn) < '50:00:00' ``` The second row should be returned because it's lesser than 50 hours, but the first row, which the timediff is more than 50 hours keep returning as well. ``` 02:04:57 15:10:49 125:00:25 ``` It returns all sort of value, including those larger than 50 What query should I be using? Thank you

Original source