I am new to Python and also dateutil
module. I am passing the following arguments:
disclosure_start_date = resultsDict['fd_disclosure_start_date']
disclosure_end_date = datetime.datetime.now()
disclosure_dates = [dt for dt in rrule(MONTHLY, dtstart=disclosure_start_date, until=disclosure_end_date)]
Here disclosure_start_date = 2012-10-31 00:00:00
which converted to datetime is datetime.datetime(2012, 10, 31, 0, 0)
End date is as of now.
When I use:
disclosure_dates = [dt for dt in rrule(MONTHLY, dtstart=disclosure_start_date, until=disclosure_end_date)]
I get the dates for every other month or 2 months apart. The result is:
>>> list(disclosure_dates)
[datetime.datetime(2012, 10, 31, 0, 0),
datetime.datetime(2012, 12, 31, 0, 0),
datetime.datetime(2013, 1, 31, 0, 0),
datetime.datetime(2013, 3, 31, 0, 0),
datetime.datetime(2013, 5, 31, 0, 0),
datetime.datetime(2013, 7, 31, 0, 0),
datetime.datetime(2013, 8, 31, 0, 0),
datetime.datetime(2013, 10, 31, 0, 0),
datetime.datetime(2013, 12, 31, 0, 0),
datetime.datetime(2014, 1, 31, 0, 0),
datetime.datetime(2014, 3, 31, 0, 0),
datetime.datetime(2014, 5, 31, 0, 0),
datetime.datetime(2014, 7, 31, 0, 0),
datetime.datetime(2014, 8, 31, 0, 0),
datetime.datetime(2014, 10, 31, 0, 0),
datetime.datetime(2014, 12, 31, 0, 0),
datetime.datetime(2015, 1, 31, 0, 0),
datetime.datetime(2015, 3, 31, 0, 0),
datetime.datetime(2015, 5, 31, 0, 0),
datetime.datetime(2015, 7, 31, 0, 0),
datetime.datetime(2015, 8, 31, 0, 0),
datetime.datetime(2015, 10, 31, 0, 0),
datetime.datetime(2015, 12, 31, 0, 0),
datetime.datetime(2016, 1, 31, 0, 0),
datetime.datetime(2016, 3, 31, 0, 0),
datetime.datetime(2016, 5, 31, 0, 0)]
I am not sure what I am doing wrong. Can someone please point out the mistake here?
RRULE
by a mode that falls back to the last day of a month if a day doesn't exist. The ruleFREQ=MONTHLY;RSCALE=GREGORIAN;SKIP=BACKWARD;BYMONTHDAY=30
would do that. In February this would result in the 28th (or 29th in leap years). Unfortunately there is not much support for this yet. – Stria