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 and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogplay
  • LinkedIn
This entry was posted in Programming, SQL. Bookmark the permalink.

2 Responses to T-SQL: Calculate Hours, Mins and Secs from StartTime and EndTime

  1. RaiulBaztepo says:

    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. PiterKokoniz says:

    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