Given a start and end time, I want to know how many minutes in a given hour are covered.
create function CalcMinsInHour(@start datetime, @end datetime, @hour int)
returns int
as
begin
--Looking for best way to write this part
end
CalcMinsInHour('2012-01-18 8:15', '2012-01-18 10:30', 7) should return 0
CalcMinsInHour('2012-01-18 8:15', '2012-01-18 10:30', 8) should return 45
CalcMinsInHour('2012-01-18 8:15', '2012-01-18 10:30', 9) should return 60
CalcMinsInHour('2012-01-18 8:15', '2012-01-18 10:30', 10) should return 30
CalcMinsInHour('2012-01-18 8:15', '2012-01-18 10:30', 11) should return 0
Edit: @Start and @End represent employee clock in/out times. So yes they can span two days when they work past midnight, but not more than that.