您可以使用TIME_FORMAT()。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> PunchIn time, -> PunchOut time, -> Launch time -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('9:00','6:00','1:00:00'); mysql> insert into DemoTable values('9:30','6:10','00:30:00');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+----------+----------+----------+ | PunchIn | PunchOut | Launch | +----------+----------+----------+ | 09:00:00 | 06:00:00 | 01:00:00 | | 09:30:00 | 06:10:00 | 00:30:00 | +----------+----------+----------+ 2 rows in set (0.00 sec)
这是查询以进行正确的时间计算-
mysql> SELECT TIME_FORMAT(TIMEDIFF(TIMEDIFF(PunchIn,PunchOut), Launch), '%H:%i') as TimeDiff from DemoTable;
输出结果
+----------+ | TimeDiff | +----------+ | 02:00 | | 02:50 | +----------+ 2 rows in set (0.00 sec)