I'm not so sure sql can do this easily, but I'm sure a stored procedure or a really funky view might pull it off. I'd do it in PHP first to prototype it, then probably just use that if it's fast enough.
First, do we count holidays? Can a start or end date fall on a weekend?
Here's the basic mathod:
Count all the raw days between now and then. divide by 7, take the integer you get back and multiply by 5. For instance, let's say the first date is March 11 2000, and the second date is Sep 20 2000.
We can use mktime to find the difference in the two dates:
$time1=mktime(0,0,0,3,11,2000); # mar 11
$time2=mktime(0,0,0,9,20,2000); # sep 18
$julian1=date("z",$time1);
$julian2=date("z",$time2);
print $julian2-$julian1;
outputs 191
will give us the raw number of days between two dates. Next we find the number of weeks. Each whole week consisted of 5 business days minus whatever holidays there were. We'll subtract holidays later, first, we'll divide 193/7 and take the integer portion for now. That gives us 27.3, and at 5 days for each that's 135 days. Now on to the fractional portion.
What we need to know now is which days of the week did the begin and end dates fall on, and if a weekend fell in between them.
We can use the date() functions "w" formatting string to get the day of the week like so:
$dow1 = date("w",$time1);
$dow2 = date("w",$time2);
'0' is sunday, 6 is saturday.
If the second day of the week ($dow2) comes after the first, we just force a 0 (sunday) in $dow1 up to 1 (monday) and a 6 (saturday) in the second $dow2 to be 5 (Friday) and subtract.
If $dow2 comes earlier in the week than $dow1, then we know that a weekend comes in between them. Just add 7 to the $dow2, then subtract each other, and if either date is a weekend, subract one more day for each that is.
Next subtract out the holidays and three day weekends and you've got your answer.