I have a situation where I have 4 columns 1. Date 2. Start time 3. End time 4. Time in min

Now I am calculating time diff based on start time. I got a situation where start time is 16:00 and end time is 03:00 and when am calculating minutes it is coming in negative. But as per process it is correct batch started in evening and closed n in morning.

I don't have any other dates please suggest how to handle this

declare @d date, @s time, @e time

select @d = '06/22/15', @s = '16:00', @e = '03:00'

select case when @s <= @e then datediff(mi, @s, @e) else datediff(mi, cast(@s as datetime), dateadd(dd, 1, cast(@e as datetime))) end

Please don't CROSS POST. A lot of us monitor all the forums. All you're doing is making it more difficult for people to help you and it causes the answers for the given problem to be split up for other folks looking for help on the same subject.

For those interested, another answer is available at the following URL for the same question.