Wednesday, April 9, 2014

How to split minutes into days, hours and minutes in tsql


Declare @theMinutes int
Set @theMinutes = 2147483647

Select convert(varchar(15), @theMinutes / 1440 ) +' Days'
       + ' ' + REPLICATE('0', 2 - DATALENGTH(convert(varchar(2), (@theMinutes % 1440) / 60 ))) + convert(varchar(2), (@theMinutes % 1440) / 60 ) + ' Hours '
       + ' ' + REPLICATE('0', 2 - DATALENGTH(convert(varchar(2), (@theMinutes % 60)))) + convert(varchar(2), (@theMinutes % 60)) + ' Minutes 'as Days_Hours_Minutes

No comments: