Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 convert

Author  Topic 

asobreiro
Starting Member

2 Posts

Posted - 2012-12-20 : 14:26:44
hello
how do you make a function to convert seconds into hours, minutes and seconds???

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-20 : 14:34:24
[code]
CREATE FUNCTION GetTime
(
@Seconds int
)
RETURNS varchar(100)
AS
BEGIN
DECLARE @TimeVal varchar(100),@dateVal datetime

SET @dateVal = DATEADD(ss,@Seconds,0)
SET @TimeVal = CAST(DATEDIFF(dd,0,@dateVal)* 24 + DATEPART(hh,@dateVal) AS varchar(5)) + ':' + DATENAME(n,@dateVal) + ':' + DATENAME(ss,@DateVal)

RETURN @TimeVal
END
[/code]



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
Go to Top of Page

asobreiro
Starting Member

2 Posts

Posted - 2012-12-20 : 15:14:35
Thank you very much
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-21 : 00:46:49
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -