A script to convert seconds into human readable format (HH:MM:SS) / text…

If you need to convert seconds to a human readable format programmatically, then please use below steps:

Step 1: Create a function as below:

create function [dbo].[udf_sec]
(@duration int)
returns varchar(8)
as
begin
return (select CONVERT(varchar(8),DATEADD(second,@duration,0),114))
end
go

Step 2: Use this function as below whenever the conversion is needed.

Syntax:

select [dbo].[udf_sec] ()

Example:

select [dbo].[udf_sec] (10000)
Output:  02:46:40

Comments