minutes to time in sql server
- by Luca Romagnoli
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?