Reputation: 2774
How can I get the result bellow:
SELECT CONVERT(VARCHAR(8),DateAdd(MINUTE, 8400, '00:00:00'),108)
Like: HH:MM
? In this case it should return 140:00
.
Thanks
Upvotes: 0
Views: 56
Reputation: 558
Try this
Declare @Minutes int = 398;
SELECT REPLACE(CONVERT(NUMERIC(18, 2), @Minutes / 60 + (@Minutes % 60) / 100.0),'.',':')
Output:
6:38
Upvotes: 0
Reputation: 49270
You can use /
and %
to get the hours and minutes. Use replicate
in case the %
returns a value of length 1
.
select cast(minutescol/60 as varchar(100)) + ':' +
replicate('0', 2-len(minutescol%60)) + cast(minutescol%60 as varchar(100))
Upvotes: 2