i have a table data like this
(int) (time) [mySQL datatype]
Id Duration
------------------
1 00:10:00
2 10:10:00
3 03:00:00
4 04:13:00
i want to calculate the total duration from this table, how can we do it. like 17:33:00. Could anybody please provide mysql query to calculate this.
To calculate the difference between the timestamps in MySQL, use the TIMESTAMPDIFF(unit, start, end) function. The unit argument can be MICROSECOND , SECOND , MINUTE , HOUR , DAY , WEEK , MONTH , QUARTER , or YEAR . To get the difference in seconds as we have done here, choose SECOND .
MySQL TIMEDIFF() Function The TIMEDIFF() function returns the difference between two time/datetime expressions. Note: time1 and time2 should be in the same format, and the calculation is time1 - time2.
Try converting to seconds, summing, then converting back to a time:
SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(Duration)))
FROM Table1
Result:
17:33:00
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With