Last active
May 17, 2019 19:16
-
-
Save mburbea/e4724d57e8cb17de7c117ee161d27310 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create function fn_workday(@start datetime,@daysToAdd int) | |
returns table | |
with schemabinding as | |
return select workday=dateadd(d,@daysToAdd + ((abs(@daysToAdd)+d-2)/5)*2*sign(@daysToAdd)-d/7,@start) | |
from (select d= 4 - sign(@daysToAdd)*(4-datepart(dw,@start))) x; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment