我想问一下如何在几分钟内找到两个字段的时差。例如,在'in'字段填写2014-07-12 19:00:00,并在'out'字段填写2014-07-12 20:30:00,时差将自动保存在'duration'字段中< / p>
----in--------------|-------out-----------| duration
2014-07-12 19:00:00 | 0000-00-00 00:00:00 | 0
--------------------------------------------------
当我点击更新按钮时,它会更新,如
-------in-----------|---------out---------| duration
2014-07-12 19:00:00 | 2014-07-12 20:30:00 | 90
--------------------------------------------------
谢谢
答案 0 :(得分:0)
TIME_TO_SEC功能手册。
SELECT (TIME_TO_SEC(`in`)-TIME_TO_SEC(`out`))/60 AS duration FROM TABLE_NAME ;
答案 1 :(得分:0)
您可以使用TIMESTAMPDIFF
功能,如下所示:
SELECT
TIMESTAMPDIFF(MINUTE, in, out) duration
FROM mytable;
<强>参考强>: