Technical Article

Function to return a date without end-of-week

,

This funciont return a date without end-of-week , it is useful to calculate a new date for any payment!
YOU CALL with 'dias_uteis(getdate(), 5)' and will get five useful days after today

CREATE FUNCTION [DBO].[DIAS_UTEIS]
  (@DATAINI DATETIME, @QTDDIAS INT)  
RETURNS DATETIME  
AS  
BEGIN 

DECLARE @DW  INT
DECLARE @VAL DATETIME

 SET @DW = DATEPART(WEEKDAY , @DATAINI)  - 1
 SET @VAL =  @DATAINI + @QTDDIAS+((@QTDDIAS -1 + @DW) /  5)   * 2 

 RETURN  ( @VAL)
END

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating