15,749,203 members
0.00/5 (No votes)
See more:
Hi all,
I have a select query that has DURATION column to calculate number of Minutes . I want to convert those minutes to hh:mm format.

Duration has values like 60, 120,150

For example:

510 becomes 08:5 hours

i have tried below query but am not getting the exact value.

select  ISNULL(CONVERT(VARCHAR,CONVERT(INT,510)/60)+':'+ RIGHT('0'+CONVERT(VARCHAR,CONVERT(INT,510)%60),2),0) AS TotalHour

my expected out put is:
8:5

please guide me were i made mistake.

thanks to all.

regards,
stellus

What I have tried:

How to convert number of minutes to hh:mm format in TSQL?
Posted
Updated 11-Jul-18 23:38pm

## Solution 1

Please see below link for a similar question asked and have good answers.

sql server 2008 - How to convert number of minutes to hh:mm format in TSQL? - Stack Overflow[^]

## Solution 2

select left(convert(time,DATEADD(minute,[column_name],0)),5) as [Time] from [tbl_name]

## Solution 3

SQL
DECLARE @tm INT;

SELECT @tm =SUM(tm) FROM (
SELECT 60 AS tm UNION SELECT 120 UNION  SELECT 150
)AS hm

SELECT format(DATEADD(MINUTE,@tm,CAST(CAST(0 AS FLOAT) AS DATETIME)),'HH:mm');

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 125 Dave Kreskowiak 90 CPallini 40 Graeme_Grant 10 snorkie 10
 OriginalGriff 290 Graeme_Grant 160 Dave Kreskowiak 110 Richard MacCutchan 60 Rick York 50

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900