You can convert seconds to HH:MM:SS in various method.
Method 1
DECLARE @Seconds INT
SET @Seconds = 7600
SELECT CONVERT(VarChar(10),@Seconds/3600)
+':' + RIGHT('00'+CONVERT(VarChar(2),(@Seconds%3600)/60),2)
+':' + RIGHT('00'+CONVERT(VarChar(2),@Seconds%60),2) AS [HH:MM:SS]
GO
The result is 02:06:40
Method 2
DECLARE @Seconds INT,@Hour VarChar(10)
SET @Seconds = 87810
SET @Hour = DateDiff(HH, 0, DateAdd(SS,@Seconds,0))
SELECT STUFF(CONVERT(VarChar(8), DateAdd(SS,@Seconds,0),108),1,2,@Hour) AS [HH:MM:SS]
GO
The Result is 24:23:30
DECLARE @Seconds INT
SET @Seconds = 7600
SELECT CONVERT(VarChar(10),@Seconds/3600)
+':' + RIGHT('00'+CONVERT(VarChar(2),(@Seconds%3600)/60),2)
+':' + RIGHT('00'+CONVERT(VarChar(2),@Seconds%60),2) AS [HH:MM:SS]
GO
The result is 02:06:40
Method 2
DECLARE @Seconds INT,@Hour VarChar(10)
SET @Seconds = 87810
SET @Hour = DateDiff(HH, 0, DateAdd(SS,@Seconds,0))
SELECT STUFF(CONVERT(VarChar(8), DateAdd(SS,@Seconds,0),108),1,2,@Hour) AS [HH:MM:SS]
GO
The Result is 24:23:30
No comments:
Post a Comment