-1

something like

is_Business_day(date) returns true or false.

Community
  • 1
  • 1
H C
  • 1,138
  • 4
  • 21
  • 39

2 Answers2

0

Use the date.weekday() function to get the weekday that a date is on. Monday is 0 and Sunday is 6, so a business day would be mydate.weekday() < 5

Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
  • this doesn't consider holidays right? Is there a way to check for valid business day? – H C Oct 31 '15 at 21:06
  • 1
    @HC That's very nation-specific; countries don't celebrate the same holidays. I doubt Python includes a list of every country's holidays. – Colonel Thirty Two Oct 31 '15 at 21:07
  • @H C: [_Best free library or database to determine if a date is a US or international holiday?_](http://stackoverflow.com/questions/736852/best-free-library-or-database-to-determine-if-a-date-is-a-us-or-international-ho) might help with the holiday determination. It looks like there's only 11 in the US, so you could easily create a table of them to check against. – martineau Oct 31 '15 at 21:56
0

I found this solution:

from bdateutil import isbday

isbday(date, holidays = holidays.US())
H C
  • 1,138
  • 4
  • 21
  • 39