- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 sum time in MySQL by converting into seconds?
To convert time to seconds, use the TIME_TO_SEC() method. Let us first create a table −
mysql> create table DemoTable -> ( -> ArrivalTime time -> ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('04:10:00'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('05:20:50'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('06:40:10'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+-------------+ | ArrivalTime | +-------------+ | 04:10:00 | | 05:20:50 | | 06:40:10 | +-------------+ 3 rows in set (0.00 sec)
Following is the query to calculate the sum of time in MySQL −
mysql> select SEC_TO_TIME( SUM( TIME_TO_SEC( ArrivalTime) ) ) from DemoTable;
Output
+-------------------------------------------------+ | SEC_TO_TIME( SUM( TIME_TO_SEC( ArrivalTime) ) ) | +-------------------------------------------------+ | 16:11:00 | +-------------------------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- Converting seconds into days, hours, minutes and seconds in C++
- C++ Program for converting hours into minutes and seconds
- How to calculate time based on seconds in MySQL?
- Remove seconds from time field in MySQL?
- Using Time datatype in MySQL without seconds?
- MySQL query to extract time in a format without seconds
- What is the best way to convert seconds into (Hour:Minutes:Seconds:Milliseconds) time in C#?
- In MySQL, how can I convert a number of seconds into TIMESTAMP?
- How to order by date and time in MySQL?
- How to convert time seconds to h:m:s format in Python?
- How to get current date/time in seconds in JavaScript?
- How to get time difference between two timestamps in seconds?
- Converting seconds in years days hours and minutes in JavaScript
- How to sum rows of VARCHAR datatype or TIME datatype in MySQL?
- How to group by date regardless of time in MySQL?

Advertisements