在MySQL中创建表并实现TIMESTAMPDIFF()?
该TIMESTAMPDIFF()
计算两个日期或日期时间表达式之间的差异。让我们首先创建一个表-
mysql> create table DemoTable665( PunchInTime datetime, PunchOutTime datetime, Details INT(11) AS (ABS(TIMESTAMPDIFF(second,PunchInTime,PunchOutTime))) )ENGINE=MyISAM;
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable665(PunchInTime,PunchOutTime) values('2019-09-21 9:30:10','2019-09-21 04:34:56'); mysql> insert into DemoTable665(PunchInTime,PunchOutTime) values('2019-11-11 10:00:20','2019-11-11 05:30:16');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable665;
这将产生以下输出-
+---------------------+---------------------+---------+ | PunchInTime | PunchOutTime | Details | +---------------------+---------------------+---------+ | 2019-09-21 09:30:10 | 2019-09-21 04:34:56 | 17714 | | 2019-11-11 10:00:20 | 2019-11-11 05:30:16 | 16204 | +---------------------+---------------------+---------+ 2 rows in set (0.00 sec)