The TIMESTAMPDIFF() calculates the difference between two dates or datetime expressions. Let us first create a table −
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 some records in the table using insert command −
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)
Display all records from the table using select statement −
mysql> select *from DemoTable665;
This will produce the following output −
+---------------------+---------------------+---------+ | 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)