以下代码是从不同的帖子创建的,但我现在有一个单独的问题。这段代码的作用基本上是花费2个日期并从中减去周末以获得从开始到结束时间(不包括周末)的总分钟数。我现在想说的是,因为我工作一天有11个小时,所以我想每天只计算11个小时。我得到的结果如下(我添加了列名,只是让你知道它们是什么):
@AllMins @MinDays
2173 1.50902777777778
由于工作日有660分钟或工作日不工作780分钟,我需要从总时间中减去这个。所以,1天将是2173-780,但我也需要在当天获得.50902777777778分钟。有什么建议吗?
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '2010-08-02 00:00:00.000'
SET @EndDate = '2010-08-03 12:13:12.123'
--How many minutes are between order start and end time including non working time
DECLARE @AllMins INT
--Declares how many minutes are in a day and makes it float to get remainder minutes when divided
DECLARE @MinsInDay FLOAT
SET @MinsInDay = 1440
--Finds how many minutes are between start and end time excluding weekends and assignes to variable
SET @AllMins = ((DATEDIFF(mi, @StartDate, @EndDate))
-(((DATEDIFF(wk, @StartDate, @EndDate) * 2) * 24) * 60)
-(((CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END) * 24) * 60)
-(((CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END) * 24) * 60))
--Calculates how many days have elapsed in the minutes that the order has taken
DECLARE @MinDays FLOAT
SET @MinDays = (@AllMins/@MinsInDay)
SELECT
@AllMins
,@MinDays
答案 0 :(得分:2)
您在寻找
吗?@AllMins - (integer portion of (@MinDays) * 780) - (fractional portion of (@MinDays) * 360)
这样你就可以从小数部分减去780分钟的部分?