
- 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
How to 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)
- Related Questions & Answers
- Calculate age based on date of birth in MySQL?
- How to sum time in MySQL by converting into seconds?
- Using Time datatype in MySQL without seconds?
- Remove seconds from time field in MySQL?
- Calculate total time duration (add time) in MySQL?
- MySQL query to extract time in a format without seconds
- How to calculate the difference between time in different MySQL columns?
- How to sum based on field value in MySQL?
- How to convert time seconds to h:m:s format in Python?
- How to get current date/time in seconds in JavaScript?
- Calculate average from JSON data based on multiple filters JavaScript
- How to calculate elapsed/execution time in Java?
- How to get time difference between two timestamps in seconds?
- MySQL query to return the entire date and time based on a string and format
- Replace records based on conditions in MySQL?
Advertisements