Saturday, May 18, 2013

Convert Seconds into minutes and seconds in sql server

Create  FUNCTION [dbo].[GetTimeByMinuteSec]
(   
@Sec INT   
)   
RETURNS VARCHAR(1000)   
AS   
begin
declare @timer varchar(30)
    select @timer='Min '+(RIGHT(CONVERT(CHAR(8),DATEADD(second,@Sec,0),108),5))+' Sec'
    return @timer
end


Output :-
Pass the  number of seconds in function:-

select [dbo].[DidTimeByMinuteSec] (121)
Output -
Min 02:01 Sec