I want to sum all the time differences to show the total hours worked by a volunteer. Getting a result set of time differences is easy:
Select timediff(timeOut, timeIn)
FROM volHours
WHERE username = 'skolcz'
which gives the list of times by hours but then I want to sum it up to a grand total.
So if the result set is:
12:00:00
10:00:00
10:00:00
08:00:00
It would just total 40 hours.
This there a way to do something like:
SELECT SUM(Select timediff(timeOut,timeIn)
FROM volHours
WHERE username = 'skolcz') as totalHours
?
Select SEC_TO_TIME(SUM(TIME_TO_SEC(timediff(timeOut, timeIn)))) AS totalhours
FROM volHours
WHERE username = 'skolcz'
If not then maybe:
Select SEC_TO_TIME(SELECT SUM(TIME_TO_SEC(timediff(timeOut, timeIn)))
FROM volHours
WHERE username = 'skolcz') as totalhours
You almost get the answer from Matthew, all you need to do is to add cast :
Select CAST(SUM(timediff(timeOut, timeIn)) as time) as totalhours
FROM volHours
WHERE username = 'skolcz'
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