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.

2 Replies to “T-SQL: Calculate Hours, Mins and Secs from StartTime and EndTime”

  1. Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language 😉
    See you!
    Your, Raiul Baztepo

  2. Hi !!!! 😉
    My name is Piter Kokoniz. Just want to tell, that your blog is really cool
    And want to ask you: what was the reasson for you to start this blog?
    Sorry for my bad english:)
    Thank you:)
    Piter Kokoniz, from Latvia

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.