2014-10-18 46 views
0

我已经创建了一个过程,它返回2个时间之间的时间差,例如ShiftStartTime,ShiftEndtime。如何查找总时差bwteen日期范围

现在的问题是,如果我传递2个日期范围,那么我将如何计算这两个日期之间的总shiftTime TimeDifference为我今天返回480分钟,但我想找到3天或更长时间的总ShiftDifference,那么我将如何添加TimeDifference超过1天?

CREATE PROCEDURE GetShiftTotalDuration 

@ShiftID int = 9, 
@FromDate DateTime, 
@ToDate DateTime 

AS 
BEGIN 

    Declare @TimeDifference int 
    Declare @ShiftStartTime time 
    Declare @ShiftEndTime time 

    Set @ShiftStartTime = (Select DeparmentShiftsHistory.StartTime from DeparmentShiftsHistory 
          where DeparmentShiftsHistory.Shift_ID= 9) 
    Set @ShiftEndTime = (Select DeparmentShiftsHistory.EndTime from DeparmentShiftsHistory 
          where DeparmentShiftsHistory.Shift_ID= 9) 
    Set @TimeDifference = (Select DATEDIFF(mi,@ShiftStartTime,@ShiftEndTime)) --Returns time difference in seconds 



END 
GO 
+0

ü没有提到日期之间的差使用来自date&todate的输入参数。如果我没有错,你需要补充说明在部门移动表的哪一部分,你的问题不清楚!! – 2014-10-18 06:55:09

回答

0

我会计算这些2日期间共shiftTime

你提到你会计算两个日期之间,但在你的代码的差异声明的变量作为time

Declare @ShiftStartTime time 
Declare @ShiftEndTime time 

因此DATEDIFF(mi,@ShiftStartTime,@ShiftEndTime)只有时间差异不是日期

如果你想获得你需要使用的数据类型datetime

在一个侧面说明,你已经宣布它没有在proocedure被使用的输入参数,通过Pradeep