This function works, but

# Thread: This function works, but

1. Senior Member
Join Date
Dec 1969
Posts
130

## This function works, but

This function works great and gives me a set of minutes in the format d:h:m . But, can anyone tell me how I would add a 0 in front of single numbers? When I run the function, some of the answers are like 1:8:12 (one day 8 hours and 12 minutes). I need it to read 01:08:12. Any help would be appreciated. <BR><BR>CREATE FUNCTION UDF_Seconds(@i_seconds AS INT) <BR>RETURNS VARCHAR(100) <BR>AS <BR>BEGIN <BR> DECLARE @days INT, <BR> @hours INT, <BR> @minutes INT <BR><BR>SELECT @days = @i_seconds / 86400 <BR> SELECT @hours = (@i_seconds % 86400) / 3600 <BR> SELECT @minutes = (@i_seconds % 3600) / 60 <BR><BR><BR> RETURN CAST(@days AS VARCHAR(10)) + &#039;:&#039; + <BR> CAST(@hours AS VARCHAR(10)) + &#039;:&#039; + <BR> CAST(@minutes AS VARCHAR(10)) <BR>END

2. Senior Member
Join Date
Dec 1969
Posts
2,437

## RE: This function works, but

RETURN right(&#039;0&#039; + CAST(@days AS VARCHAR(10)),2) + &#039;:&#039; +<BR> right(&#039;0&#039; + CAST(@hours AS VARCHAR(10)),2) + &#039;:&#039; +<BR> right(&#039;0&#039; + CAST(@minutes AS VARCHAR(10)),2)

3. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## RE: This function works, but

Looks good - I knew I had skimped on the part, but wasn&#039;t sure if it would matter to you (guess it did).<BR><BR>Good job, Jordan!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•