Posts Tagged ‘Hours’

h1

SQL SERVER: Display Minutes in Hour Format like HH:MM

03/23/2009


Usually, we are saving Hours in Minute Format. So if user has entered
Hour: 2 Minutes: 15. We will save 135 Minutes in Database, so we can manipulate it easily.


Now we need a report in which we need to display this minutes in HH:MM format as user has entered.

This is very simple, lets see:

DECLARE @t TABLE(Minutes INT)
INSERT INTO @t
SELECT 120
UNION ALL
SELECT 135
UNION ALL
SELECT 135
UNION ALL
SELECT 1440
UNION ALL
SELECT 640
UNION ALL
SELECT 720

SELECT Minutes / 60 as Hours,
Minutes % 60 AS Minutes
FROM @t

Let me know if it helps you in any way.