One of the tricky things about this is that
'2016-05-06' was 4 business days after
'2016-05-10' was 2 business days after
even though in both pairs of dates exactly the same total number of days passed.
So what I'd probably do to get the number of business days between date A
and date B (assuming "business day" means "any day that is not a
Saturday or Sunday")
would be to choose a "zero date", some Sunday before any date that
I would ever want to use as date A, find the number of business days between
the zero date and date B, and then subtract the number of
business days between the zero date and date A.
(Of course this is all for a certain definition of "between."
For other definitions I might use a Monday as a zero date,
or use Monday with date A and Sunday with date B, or vice versa,
whatever gave results that fit the desired definition.)
One way to find the number of business days between
a zero-date Sunday and date X is to take the total number of days
between those dates and subtract the number of Saturdays and Sundays.
For this we could use what many call "integer division."
Different programming languages give you different ways to indicate
that you want to divide one integer
x by another integer
while discarding the remainder. I'll write this operation
x // y
for the purpose of this answer; substitute the correct form in whichever
language you use.
Let the integer
x be the total number of days between the
zero date (a Sunday) and date X.
Then the number of Sundays between the zero date and date X is
x // 7,
and the number of Saturdays is
(x + 1) // 7.
The number of business days then is
f(x) = x - (x // 7) - ((x + 1) // 7)
Note that integer division doesn't follow the same distributive laws
as floating-point division (almost) does;
x - ((2*x + 1) // 7) would produce a lot of wrong answers.
The number of business days between date A and date B, which are respectively
a days and
b days after the zero date, is then
f(b) - f(a)
If you have to use Monday as a zero date then the number of business days
before date X, which is
x days after the zero date, is
f(x) - 1.