Next N business day calculation in Python

We are ignoring weekend(sat,sun) as well as holiday. But holidays is depends on reason.
User need to declare holiday in Holiday list to skip those date.

def calc_businessday(next):
from datetime import date,timedelta
holidays=[date(2013,01,01),date(2013,12,26),date(2013,8,15)]
d= date.today()
NBD=next
while NBD>0:
d+=timedelta(days=1)
#print d.weekday()
if d.weekday()>=5:
continue
if d in holidays:
continue
NBD-=1
print d

calc_businessday(n) # where n can be any valid number

About these ads
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: