在 MySQL 中创建表并实现 TIMESTAMPDIFF()?
TIMESTAMPDIFF() 计算两个日期或 datetime 表达式之间的差值。我们首先创建一个表 -
mysql> create table DemoTable665( PunchInTime datetime, PunchOutTime datetime, Details INT(11) AS (ABS(TIMESTAMPDIFF(second,PunchInTime,PunchOutTime))) )ENGINE=MyISAM; Query OK, 0 rows affected (0.23 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable665(PunchInTime,PunchOutTime) values('2019-09-21 9:30:10','2019-09-21 04:34:56'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable665(PunchInTime,PunchOutTime) values('2019-11-11 10:00:20','2019-11-11 05:30:16'); Query OK, 1 row affected (0.04 sec)
使用 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)
广告