mysql> select timestamp('2017-06-21 23:45:01') - timestamp('2017-06-21 23:44:58');
+---------------------------------------------------------------------+
| timestamp('2017-06-21 23:45:01') - timestamp('2017-06-21 23:44:58') |
+---------------------------------------------------------------------+
| 43 |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select version();
+------------+
| version() |
+------------+
| 5.7.16-log |
+------------+
1 row in set (0.00 sec)
显然,它不是timestamp
计算的。请指教。
答案 0 :(得分:1)
您必须使用TIMEDIFF()
或TIMESTAMPDIFF()
<强> DEMO 强>
SELECT TIMEDIFF(timestamp('2017-06-21 23:45:00') , timestamp('2017-06-21 23:44:58'));
-- result: 00:00:02.
SELECT TIMESTAMPDIFF(SECOND,'2017-06-21 23:45:00','2017-06-21 23:44:58');
-- result: -2