SQLTeam.com | Weblogs | Forums

Calculate Hours Worked



I have two columns, Start_Shift and End_Shift. How do I calculate the hours worked?



You did not say what datatype Start_Shift and End_Shift are. If they are DATETIME you could use DATEDIFF

SELECT DATEDIFF(HOUR, Start_Shift, End_Shift) HoursCalc


thank you for your help that has worked perfectly.

thanks again


Because of the way DATEDIFF works, it's much safer to use MINUTE rather than HOUR:

SELECT CAST(DATEDIFF(MINUTE, Start_Shift, End_Shift) / 60.0 AS decimal(6, 2)) AS HoursCalc


Thank you for your help :blush: