USE [P21]
GO

/****** Object:  UserDefinedFunction [dbo].[nutech_fn_NumberWorkDays]    Script Date: 9/23/2024 6:44:14 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		NuTech Services, LLC.
-- Create date: 02/27/2019
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[nutech_fn_NumberWorkDays]
(
    @fromdate Datetime,
    @todate Datetime
)
RETURNS INT
AS
BEGIN
	-- Declare the return variable here
	DECLARE @NumberofWorkDays Int

    SELECT @NumberofWorkDays =
       (DATEDIFF(dd, @fromdate, @todate) + 1)
      -(DATEDIFF(wk, @fromdate, @todate) * 2)
      -(CASE WHEN DATENAME(dw, @fromdate) = 'Sunday' THEN 1 ELSE 0 END)
      -(CASE WHEN DATENAME(dw, @todate) = 'Saturday' THEN 1 ELSE 0 END)

	RETURN @NumberofWorkDays

END
GO


