views:

34

answers:

1

So the scenario is as follows, I have two columns "StartHour" and "EndHour". Both are stored as Integers. F.ex values can be StartHour : 30 (clock time 00:30) and EndHour : 630 (clock time 06:30) The output I'd like from this is 360 (minutes).

I need the difference between the two fields, and I need them in minutes. I can process the data after I fetch it, but I'd rather not.

Any good ideas?

+1  A: 

You can use integer aritmethic / (Divide) and % (Modulo)

DECLARE @StartHour INT = 30
DECLARE @EndHour INT = 630

SELECT ((@EndHour / 100) * 60 + @EndHour % 100) - ((@StartHour / 100) * 60 + @StartHour % 100)
Branimir