«

»

Jan 13 2008

Print this Post

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.

Permanent link to this article: http://ramblinggeek.co.uk/2008/01/t-sql-calculate-hours-mins-and-secs-from-starttime-and-endtime/

2 comments

  1. RaiulBaztepo

    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

    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

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>