How to find all week numbers that are first week of month in a year python

Viewed 2248

I want to create a event that falls on Sunday of every first week of months.

This is what I am doing for a particular week number which is first week of june to get date:

from datetime import datetime
myDate = "2017 22 0"
# here `2017` is year, `22` is week number and `0` =sunday is week day
datetime.strptime(myDate, "%Y %W %w")

#output...
datetime.datetime(2017, 6, 4, 0, 0)

So I need a list of all week numbers that are first week of month so I can loop on it and get desire dates.

Adding More information

I want a method which return list of week numbers which are first week of month where first week means week has first sunday.

def get_week_number(year=2017, day=0):
   #day 0 means sunday
   ...
   ...
   return [1, 5, 9, 13, 18, 22, ...]  
2 Answers
Related