Skip to content

Instantly share code, notes, and snippets.

@pablotolentino
Created March 24, 2021 23:50
Show Gist options
  • Save pablotolentino/5b85e0ad90132b119bddb93d346f050d to your computer and use it in GitHub Desktop.
Save pablotolentino/5b85e0ad90132b119bddb93d346f050d to your computer and use it in GitHub Desktop.
CREATE FUNCTION [dbo].[DiasLaborales]
(@FechaInicial DATE,
@FechaFinal DATE )
RETURNS INT
AS
BEGIN
DECLARE @fecha DATE
DECLARE @diaslaborales int
SET @fecha = @FechaInicial
SET @diaslaborales = 0
WHILE (@fecha<>DATEADD(day,1,@FechaFinal))
BEGIN
IF (DATEPART(dw,@fecha) NOT IN (7,1))
BEGIN
SET @diaslaborales = @diaslaborales +1
END
SET @fecha = DATEADD(day,1,@fecha)
END
RETURN @diaslaborales
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment