检查并计算sql 2005中datetime之间的时间段

时间:2013-05-17 11:03:47

标签: sql datetime between

我需要检查日期时间和工作时间之间的工作时间是否超过8小时。

示例数据:

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 )

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

试试这个:T-SQL DateDiff - partition by "full hours ago", rather than "times minutes turned 00 since"

基本上,DATEDIFF(HOUR,endTime,startTime)。然后,从8减去你的结果得到差异(如果它们是“在”时间之下,差异将是负数)。