minutes to time in sql server

Posted by Luca Romagnoli on Stack Overflow See other posts from Stack Overflow or by Luca Romagnoli
Published on 2010-05-31T15:45:47Z Indexed on 2010/05/31 16:03 UTC
Read the original article Hit count: 155

Filed under:
|
|

i've created a function for convert minutes (smallint) in time (varchar(5)) like 58 -> 00:58

   set QUOTED_IDENTIFIER ON
GO
Create FUNCTION [dbo].[IntToMinutes]
(
    @m smallint 
)  
RETURNS nvarchar(5)
AS  
BEGIN
    DECLARE @c nvarchar(5)
     SET @c = CAST((@m / 60) as varchar(2)) + ':' + CAST((@m % 60) as varchar(2))       
     RETURN @c
END

The problem is when there are minutes < 10 in time like 9 the result of this function is 0:9 i want that the format is 00:09

how can i do that?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server