BrianFord
asked on
Summing time fields to get total time
Using MySQL.
I have a field called 'duration' that has data in the format '1899-12-31 00:08:55'
I ned to sum up the TIME portion of this field and show th result as HH:MM:SS, what would the sql synax be fo this??
I have a field called 'duration' that has data in the format '1899-12-31 00:08:55'
I ned to sum up the TIME portion of this field and show th result as HH:MM:SS, what would the sql synax be fo this??
Is the duration field datetime or varchar?
maybe this:
SEC_TO_TIME(
hour(mydt)*60*60 +
minute(mydt)*60 +
second(mtdt)
)
check all date & time functions here
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_hour
SEC_TO_TIME(
hour(mydt)*60*60 +
minute(mydt)*60 +
second(mtdt)
)
check all date & time functions here
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_hour
something like this:
select
SEC_TO_TIME(sum(
hour(mydt)*60*60 +
minute(mydt)*60 +
second(mtdt)
)
)
from my table where ...
select
SEC_TO_TIME(sum(
hour(mydt)*60*60 +
minute(mydt)*60 +
second(mtdt)
)
)
from my table where ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect thanks very much :)
but my solution is basically the same one that you posted :(
TIME(mydt) = hour(mydt)*60*60 + minute(mydt)*60 + second(mtdt)
TIME(mydt) = hour(mydt)*60*60 + minute(mydt)*60 + second(mtdt)
ASKER
My appologies,
I actually mis-read your solution, if there is a way for me to split the points at this stage I'm happy to do so, soryy :(
I actually mis-read your solution, if there is a way for me to split the points at this stage I'm happy to do so, soryy :(
I'm sorry HainKurt, I didn't want to steal your solution, I was unaware of it, we just posted at the same time (you faster, it took me more time to explain my solution).
I'd be happy to share my points with you, if possible :)
BrianFord, glad to help! :)
I'd be happy to share my points with you, if possible :)
BrianFord, glad to help! :)