I am trying find an efficient way of creating a list of dates only including the first day of the month for a given period. Something like this but better:
impor
You can use relativedelta from dateutil, and then create a function to use any date range:
from datetime import date
from dateutil.relativedelta import relativedelta
def mthStList(start_date, end_date):
stdt_list = []
cur_date = start_date.replace(day=1) # sets date range to start of month
while cur_date <= end_date:
stdt_list.append(cur_date)
cur_date += relativedelta(months=+1)
return stdt_list
mthStList(date(2012, 5, 26), date.today())