Here's one way of doing it. Note (1) you don't say what you expect if the start date is NOT a workday. (2) Your example is wrong.
C:\junk\so>type workdays.py
import datetime
def add_workdays(adate, nworkdays):
if nworkdays < 0:
incr = -1
nworkdays = - nworkdays
else:
incr = 1
delta_weeks, delta_days = divmod(nworkdays, 5)
one_day = datetime.timedelta(days=incr)
if delta_weeks:
wdate = adate + one_day * 7 * delta_weeks
else:
wdate = adate
while delta_days:
wdate += one_day
if wdate.weekday() < 5: # Mon-Fri
delta_days -= 1
return wdate
if __name__ == "__main__":
start = datetime.date(2009, 8, 21)
for i in range(10, -19, -1):
end = add_workdays(start, i)
print "%3d %s" % (i, end.strftime("%a %Y-%m-%d"))
C:\junk\so>\python26\python workdays.py
10 Fri 2009-09-04
9 Thu 2009-09-03
8 Wed 2009-09-02
7 Tue 2009-09-01
6 Mon 2009-08-31
5 Fri 2009-08-28
4 Thu 2009-08-27
3 Wed 2009-08-26
2 Tue 2009-08-25
1 Mon 2009-08-24
0 Fri 2009-08-21
-1 Thu 2009-08-20
-2 Wed 2009-08-19
-3 Tue 2009-08-18
-4 Mon 2009-08-17
-5 Fri 2009-08-14
-6 Thu 2009-08-13
-7 Wed 2009-08-12
-8 Tue 2009-08-11
-9 Mon 2009-08-10
-10 Fri 2009-08-07
-11 Thu 2009-08-06
-12 Wed 2009-08-05
-13 Tue 2009-08-04
-14 Mon 2009-08-03
-15 Fri 2009-07-31
-16 Thu 2009-07-30
-17 Wed 2009-07-29
-18 Tue 2009-07-28
C:\junk\so>