
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a table in MySQL and implement TIMESTAMPDIFF()?
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)
- Related Questions & Answers
- INSERT INTO table if a table exists in MySQL else implement CREATE TABLE and create the table
- Implement GREATEST() in MySQL and update the table?
- Create a table in MySQL that matches another table?
- Create MySQL query to create a table from an existing table?
- Create a temporary table in a MySQL procedure?
- Create index on create table in MySQL?
- Add new MySQL table columns and create indexes?
- How to create a temporary MySQL table in a SELECT statement without a separate CREATE TABLE?
- MySQL Stored Procedure to create a table?
- Create a temporary table with dates in MySQL
- How to create a MySQL table with InnoDB engine table?
- How to create a MySQL table with MyISAM engine table?
- Create a temporary table similar to a regular table with MySQL LIKE
- How to implement CANDIDATE key in any MySQL table?
- Create a MySQL table from already created table selecting specific rows?
Advertisements