'SQL Working Days between two Dates

Hi I have the following function to work out WD between two dates. my query is...i have two dates with the same date eg. 06/07/2016 and i want WD to show as 0 but instead it is showing as 1. is there away to change how WD is worked out?

ALTER FUNCTION [dbo].[CalculateNumberOFWorkDays] (@StartDate datetime, @EndDate datetime)
RETURNS int
AS
BEGIN

 SET @StartDate = DATEADD(dd, DATEDIFF(dd, 0, @StartDate), 0) 
 SET @EndDate = DATEADD(dd, DATEDIFF(dd, 0, @EndDate), 0) 

 DECLARE @WORKDAYS INT
 SELECT @WORKDAYS = (DATEDIFF(dd, @StartDate, @EndDate) + 1)
               -(DATEDIFF(wk, @StartDate, @EndDate) * 2)
           -(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
           -(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)

 RETURN @WORKDAYS END


Solution 1:[1]

cracked it...

 SELECT @WORKDAYS = (DATEDIFF(dd, @StartDate, @EndDate) + 0)

seems to have done the job! :-)

Solution 2:[2]

Need to subtract 1.

Just like a normal SQL DATEDIFF function, the number of business days between two adjacent weekdays, say Tuesday and Wednesday, should be 1. Between Friday and Saturday, it would be 0. Between Friday and Monday it would be 1.

    declare @StartDate datetime = '1/17/19'
declare @EndDate datetime = '1/18/19'

SET @StartDate = DATEADD(dd, DATEDIFF(dd, 0, @StartDate), 0) 
 SET @EndDate = DATEADD(dd, DATEDIFF(dd, 0, @EndDate), 0) 

 DECLARE @WORKDAYS INT
 SELECT @WORKDAYS = (DATEDIFF(dd, @StartDate, @EndDate) + 1)
               -(DATEDIFF(wk, @StartDate, @EndDate) * 2)
               -1
           -(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
           -(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)

 SELECT @WORKDAYS

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sql2015
Solution 2 Caius Jard