SimonBurrell
Technical User
I hope this helps someone when trying to work out how to calculate the time difference when the endtime is the next day.
I finally worked it out (thanks to the legendary Dr Bull).
Regards
Simon
I finally worked it out (thanks to the legendary Dr Bull).
Code:
/* This returns an output in minutes. If whole hours is the result you want - change the 720 (minutes) to 12 (hours) and change the datediff datepart to hh (hours)*/
SELECT TimeDiff =
CASE
WHEN EndTime < Starttime THEN (720 -((datediff(mi,EndTime,StartTime )) - 720))
WHEN EndTime > Starttime THEN(datediff(mi, StartTime, EndTime))
END
FROM YourTable
Regards
Simon