0

I need to check if any work time period is between datetime and calculate hours between for work hours sum grater than 8 hours.

Sample data:

1. Work time: 07:00 - 17:00 and datetime for checking 06:00-22:00
Answer: 2 hour 
2. Work time: 13:00 - 23:00 and datetime for checking 06:00-22:00
Answer: 1 hour (only 1 hour is grater 8 hours and between 06:00-22:00 )
3. Work time: 19:00 - 05:00 and datetime for checking 22:00-06:00
Answer: 2 hour (only 2 hour is grater 8 hours and between 22:00-06:00 )

Any ideas?

TechDo
  • 18,398
  • 3
  • 51
  • 64
Martin
  • 1

1 Answers1

0

Try this: T-SQL DateDiff - partition by "full hours ago", rather than "times minutes turned 00 since"

Basically, DATEDIFF(HOUR, endTime, startTime). Then, subtract your result from 8 to get the difference (if they were "under" time, the difference will be negative).

Community
  • 1
  • 1
SubSevn
  • 1,008
  • 2
  • 10
  • 27