Mihir Mihir - 19 days ago 6
MySQL Question

How to get sum of times in mysql?

How to calculate sum of times store in a column in mysql ?
table name : timesheet

+----------+
| hours |
+----------+
| 02:00:00 |
| 03:30:00 |
| 04:30:00 |
| 05:30:00 |
| 06:00:00 |
| 07:00:00 |
| 08:00:00 |
| 09:00:00 |
+----------+


I need output :
45:30:00
.
I tried with the below sql

select sum(hours) from timesheet ;


But it is showing
449000

can you please correct me with proper sql ?

Answer

You can use SEC_TO_TIME and TIME_TO_SEC date time functions

select SEC_TO_TIME(sum(TIME_TO_SEC(hours))) from timesheet ;