
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Calculate Time Based on Seconds in MySQL
Let us first create a table −
mysql> create table DemoTable ( Logouttime time ); Query OK, 0 rows affected (0.62 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('5:50:00'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('6:10:10'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('8:00:50'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------+ | Logouttime | +------------+ | 05:50:00 | | 06:10:10 | | 08:00:50 | +------------+ 3 rows in set (0.00 sec)
Following is the query to calculate time-based on seconds in MySQL −
mysql> select sec_to_time(sum(time_to_sec(Logouttime))) from DemoTable;
This will produce the following output −
+-------------------------------------------+ | sec_to_time(sum(time_to_sec(Logouttime))) | +-------------------------------------------+ | 20:01:00 | +-------------------------------------------+ 1 row in set (0.80 sec)
Advertisements