I have two datetime objects; a start date and an end date. I need to enumerate the days, weeks and months between the two, inclusive.
Ideally the results would be in datetime form, though any compatible form is fine. Weeks and months are represented by a date corresponding to the first day of the week/month, where Monday is the first day of a week, as in ISO-8601. This means that the result may contain a date earlier than the start date.
For example, given 2010-11-28 to 2010-12-01, the results would be as follows:
days: 2010-11-28, 2010-11-29, 2010-11-30, 2010-12-01
weeks: 2010-11-22, 2010-11-29
months: 2010-11-01, 2010-12-01
I realize that the list of days is by itself straightforward, but I’d like a clean and consistent solution that uses a similar approach for all three. It seems like the calendar module should be useful, but I’m not seeing a good way to use it for this purpose.
Using dateutil:
yields