· 1 min read
T-SQL: Calculate Hours, Mins and Secs from StartTime and EndTime
select
sum(TotalSeconds) / 3600 as Hours,
(sum(TotalSeconds) % 3600) / 60 as Minutes,
sum(TotalSeconds) % 60 as Seconds
from
(
select ArrivalTime, DepartureTime, DateDiff(second, ArrivalTime, DepartureTime) as TotalSeconds
from SSR
where CustomerID = 10
) x
Thanks to this site for the heads up.
Share: