Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HH:MM:SS faq

Status
Not open for further replies.

AlexCuse

Programmer
Apr 13, 2006
5,416
US
Hi All,

Just got an email today that my faq was approved. It's basically an addendum to one written by SQLBill to convert seconds to normal time format. I am not sure I will ever need to use this, but I would love to hear any feedback on how to make it better (or ways to break it %-( )

Thanks

Alex

Oh yeah , here is the link faq183-6519

Ignorance of certain subjects is a great part of wisdom
 
This is what I would do:

CREATE FUNCTION SecToTime (@SEC INT)
RETURNS VARCHAR(12)
AS
BEGIN
DECLARE @MIN INT,
@HOUR INT,
@FILL CHAR(2)

SET @FILL = '00'
SET @HOUR = @SEC / 3600
SET @MIN = @SEC / 60
SET @SEC = @SEC % 60

RETURN (RIGHT(@FILL + CAST(@HOUR AS VARCHAR(2)), 2) + ':' +
RIGHT(@FILL + CAST(@MIN AS VARCHAR(2)), 2) + ':' +
RIGHT(@FILL + CAST(@SEC AS VARCHAR(2)), 2))
END



Geert Verhoeven
Consultant @ Ausy Belgium

My Personal Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top