0

I'd like to check the days for a given week_number. For an instance, if I input year 2017 and weekNumber 43, I would like to receive all dates for that week, in this case 22-28.10.2017.

Is it possible to do in Python? Was trying to find something using google, but unsuccessfully.

Thanks in advance,

Vba_Beg
  • 383
  • 1
  • 4
  • 12

1 Answers1

2
from datetime import date, timedelta
def get_start_end_dates(year, week):
     d = date(year,1,1)
     if(d.weekday()<= 3):
         d = d - timedelta(d.weekday())             
     else:
         d = d + timedelta(7-d.weekday())
     dlt = timedelta(days = (week-1)*7)
     return d + dlt,  d + dlt + timedelta(days=6)

print get_start_end_dates(2017,43)
Dharmesh Fumakiya
  • 2,070
  • 1
  • 10
  • 17