if you really and truly want to count
business days. then you will need a calendar table to store holidays
if you just want monday through friday regardless of whether it's a holiday, then yes, there is a way, but it is exceedingly complicated
use DAYOFWEEK(date) or WEEKDAY(date) to get the day of the week of both the original date and today
do the subtraction as you currently have it
adjust the answer by a certain number based on
- the number of full weeks in the answer
(divide by seven, multiply by two)
- whether the original date's day number is greater than today's day number
for example, february 29 is day 60, today is day 33, difference is 27, you have to throw away 27/7 = 4, times 2 is 8 days, and the adjustment is 0 days because today is weekday 2 and feb 29 is weekday 1, so 27 - 8 = 19
okay, i admit, i cheated, i looked at my wall calendar
like i said, very complicated
with a calendar table, however...
Code:
caldate wkday holiday
2004-02-01 1
2004-02-02 2
2004-02-03 3
2004-02-04 4
2004-02-05 5
2004-02-06 6
2004-02-07 7
2004-02-08 1
2004-02-09 2
2004-02-10 3
2004-02-11 4
2004-02-12 5
2004-02-13 6
2004-02-14 7
2004-02-15 1
2004-02-16 2 President's Day
2004-02-17 3
2004-02-18 4
2004-02-19 5
2004-02-20 6
2004-02-21 7
2004-02-22 1
2004-02-23 2
2004-02-24 3
2004-02-25 4
2004-02-26 5
2004-02-27 6
2004-02-28 7
2004-02-29 1
2004-03-01 2
2004-03-02 3
2004-03-03 4
2004-03-04 5
2004-03-05 6
2004-03-06 7
the query is really simple:
Code:
select count(*)
from calendar
where caldate between current_date and 'yourdate'
and weekday in (2,3,4,5,6)
and holiday is null