The following code has been created from a different post, but I now have a separate issue. What this code does is basically takes the 2 dates and subtracts weekends from it to get the overall time elapsed in minutes from start to end time excluding weekends. I am now trying to say since there is 11 hours in a work day for me I want to only count 11 hours per day. The results I get are as follows(I added the column names just so you know what they are):
@AllMins @MinDays
2173 1.50902777777778
Since there are 660 minutes in a work day or 780 minutes not working in a work day I need to subtract this from the overall time. So, 1 day would be 2173-780, but I also need to get the .50902777777778 minutes in the day. Any suggestions?
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