Home > Mobile >  SQL query - converting seconds to HH:MM:SS
SQL query - converting seconds to HH:MM:SS

Time:02-10

I have the following query that returns a total seconds value (up to 86400 seconds (1 day))

I want to convert this to an HH:MM:SS value. Any help is appreciated.

(SELECT FIRST TSS.TotalDrivingTime 
 FROM HLG01_TR_TachographShiftSummary TSS
 WHERE TSS.DriverID = TRD.DriverID
   AND (CONVERT(date, TSS.PeriodStart)) = S.LoadDate)

CodePudding user response:

in sqlserver you can use:

declare @Seconds as int = 86400; SELECT CONVERT(time(0), DATEADD(SECOND, @Seconds, 0)) as 'hh:mm:ss'

and in mysql

SELECT SEC_TO_TIME(test_duration) as `Time` FORM YOUR_TABLE;

or

FROM_UNIXTIME(unix_timestamp, '%h:%i:%s')

How to convert time in seconds to HH:MM:SS format in MySQL?

https://www.sqlservercentral.com/forums/reply/1459738

CodePudding user response:

you can use this

(Format(Int(Sum([Seconds])/3600),'00') & ':' & Format(Sum([Seconds]/86400),'nn:ss')) AS [Total Time]
  • Related