I'm currently trying to compute the time difference between two dates in a database in hours. For example, 6:00 AM to 8:00 AM is 2 hours.
I have this part solved, but it seems the problem I am having is when I try to compute the time between two entries in my database.
2016-09-21 08:00:00.000 is StartTime
2016-08-16 12:00:00.000 is End Time
SELECT TherapyGroups.Name as GroupName,
COUNT(*) as NumberAttended,
SUM(DATEDIFF(hh, TherapyDailyNotes.StartTime, TherapyDailyNotes.EndTime)) % 24 as ContactHours
DATEPART can extract just the hour value:
SELECT ContactHours = abs( datepart(hour, TherapyDailyNotes.StartTime) - datepart(hour, TherapyDailyNotes.EndTime) ) FROM TherapyDailyNotes