Pages

Thursday, November 20, 2008

Convert integer in time In Sql Server

Convert Integer in time In Sql Server

Introduction : In this article i will show you how to convert Integer to time format in sql server .I have created function will return time as a string .Its takes parameter as a second in integer and return time .

CREATE function [dbo].[GetMinutesFromInt](@seconds int)  
returns  varchar(20)  
as
 begin  
   declare @time varchar(20)  
   set @time =    CASE WHEN @seconds/3600<10 THEN '0' ELSE '' END   + RTRIM(@seconds/3600)  + ':' + RIGHT('0'+RTRIM((@seconds % 3600) / 60),2)  + ':' + RIGHT('0'+RTRIM((@seconds % 3600) % 60),2)  
   return(@time) 
 end 

Call Function :

select dbo.GetMinutesFromInt(70)

Output :

00:01:10

Related Other posts