MySQL time can not be directly subtracted, if the day, minute, time difference, subtract the result is wrong
Mysql> select T1,t2,t2-t1 from MyTest; +---------------------+---------------------+-------+ | T1 | T2 | T2-t1 | +---------------------+---------------------+-------+ | 2013-04-21 16:59:33 | 2013-04-21 16:59:43 | 10 | | 2013-04-21 16:59:33 | 2013-04-21 17:00:33 | 4100 | | 2013-04-21 16:59:33 | 2013-04-21 17:59:35 | 10002 | +---------------------+---------------------+-------+
The actual MySQL time subtraction is to do an implicit conversion operation, converting time to integers, but not with unix_timestamp conversion, but directly to the date and time of the day to spell up, such as 2013-04-21 16:59:33 Direct conversion to 20130421165933, because the time is not a decimal, so the final result is meaningless, which is also caused by the results of the pit father above.
to get the correct time to subtract the second value, there are 3 ways to do this:
1, time_to_sec (Timediff (T2, T1)),
2, Timestampdiff (second, T1, T2),
3, Unix_timestamp (T2)-unix_timestamp (t1)
MySQL Time subtraction problem