-1

I need help in converting seconds to HH:MM: SS in SQL Server.

This is the code I have:

SELECT
    CONVERT(varchar(8), DATEADD(SECOND, DATEDIFF(SECOND, '2020-11-28 16:03:53.200', '2020-11-28 16:25:53.200'), 0), 114) AS Runtime

OUTPUT: 00:22:00

The above code works when the date difference is within one day, but if the date difference is more than one day then this code is not working

SELECT
    CONVERT(varchar(8), DATEADD(SECOND, DATEDIFF(SECOND, '2020-11-28 16:03:53.200', '2020-11-29 16:25:53.200'), 0), 114) AS Runtime

OUTPUT : 00:22:00

Thanks,

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Vinoth .R
  • 1
  • 2
  • SQL Server doesn't have have a timespan datatype, just a `time` data type that represents a *time* of day; therefore the value cannot be 24:00:00 or greater, as no such time exists. – Larnu Jun 01 '22 at 07:49

1 Answers1

-1

SELECT SEC_TO_TIME( seconds ); SELECT SEC_TO_TIME( seconds ); In this query, the “seconds” parameter is the number of seconds to convert. The result will be displayed in “HH:MM:SS” format.

https://stackhowto.com/mysql-how-to-convert-seconds-to-hhmmss-format/

Dale K
  • 21,987
  • 13
  • 41
  • 69
IslamYearul
  • 33
  • 1
  • 7