0
@Start_Date datetime
@End_Date  datetime

@End_Date - @Start_Date = 5 days, 3 hours, 2 min, 10 sec

How to convert it to hours:minutes:seconds?

Thanks.

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
boy boy
  • 11
  • 1
  • Here's an answer from 2009: https://stackoverflow.com/questions/1262497/how-to-convert-seconds-to-hhmmss-using-t-sql You might also be able to use the `FORMAT` function – Nick.Mc Jul 18 '18 at 05:14
  • Possible duplicate of [How to convert Seconds to HH:MM:SS using T-SQL](https://stackoverflow.com/questions/1262497/how-to-convert-seconds-to-hhmmss-using-t-sql) – Nick.Mc Jul 18 '18 at 05:14

1 Answers1

0

Thousands of ways to do this, but this is a simple one.

Assume your dates are @d1 and @d2, this will work:

select convert(varchar,floor(convert(float,@d1-@d2))*24)
   +':'+convert(varchar,datepart(minute,@d1-@d2))
   +':'+convert(varchar,datepart(second,@d1-@d2))
TomC
  • 2,759
  • 1
  • 7
  • 16