0

Need to get previous date from given without sat, sun and holidays(table).

Leave scenerio.

f_date=self.get_query_argument("from_date")
date_1 = datetime.strptime(f_date,"%Y-%m-%d")
bef_date = date_1 - timedelta(days=1)
if bef_date.weekday()==5:
   prev_date = bef_date - timedelta(days=1)
elif bef_date.weekday()==6:
   prev_date = bef_date - timedelta(days=2)
else:
   prev_date =bef_date

I got here the previous date without saturday and sunday but dono how to get it without holiday mentioned in table.

I already referred this link but struggling to omit holiday.

Advance thanks

naveenkumar.s
  • 901
  • 8
  • 17
  • Possible duplicate of [Business days in Python](http://stackoverflow.com/questions/2224742/business-days-in-python) – GWW Jul 22 '16 at 14:01
  • I need to omit holiday but the above link does not resolve this issue. – naveenkumar.s Jul 22 '16 at 14:06
  • The above link does have an example of removing holidays. – GWW Jul 22 '16 at 16:09
  • I think you are saying about this example but i cant understand to omit holiday list can you help me with my above example http://stackoverflow.com/questions/2224742/business-days-in-python – naveenkumar.s Jul 25 '16 at 07:23

1 Answers1

0

try using "in" on your table

foo = [1,2,3,4,5]
2 in foo

returns "True"

for dates

d1 = (datetime.datetime.now()-datetime.timedelta(1)).date()
d2 = (datetime.datetime.now()-datetime.timedelta(2)).date()
d3 = (datetime.datetime.now()-datetime.timedelta(3)).date()

listOfHolidays = [d1,d2,d3]

(datetime.datetime.now()-datetime.timedelta(2)).date() in listOfHolidays
Mohammad Athar
  • 1,953
  • 1
  • 15
  • 31