MySQL compares two datetime-type time intervals, in seconds:
SELECTTIME_TO_SEC (TIMEDIFF ('2017-02-09 11:24:46 ', '2017-02-09 10:23:46 '));
First read select timediff ('2017-02-09 11:24:46 ', '2017-02-09 10:23:46 ')
01:01:00
SELECT TIME_TO_SEC('01:01:00')
3660
Therefore, we know the number of seconds between the two datetime data.
If we consider that the two datetime data are first converted to their respective seconds by TIME_TO_SEC and then subtracted, isn't the same effect?
SELECT TIME_TO_SEC('2009-02-09 11:24:46')-TIME_TO_SEC('2009-02-09 10:23:46')
3660
It seems that this method is also OK, but we will observe a group of data and you will know why we cannot use this method to compare the time interval between two datetime data.
Now we use '2017-02-0811:24:46 and '2017-02-09 10:23:46 'comparison:
SELECT TIME_TO_SEC('2009-02-08 11:24:46')-TIME_TO_SEC('2009-02-09 10:23:46')
3660
It's strange that the parameter on the left is one day earlier than the parameter on the right. Why is the number of seconds subtracted or a positive value?
Originally, TIME_TO_SEC only converts the time part of datetime data to the number of seconds, and does not care who is the size of the date, so to compare two datetime data, you must first convert TimeDiff to the number of seconds, start:
SELECT TIME_TO_SEC(TIMEDIFF('2009-02-09 11:24:46','2009-02-09 10:23:46'));