I prefer the arrow
style solution here (might need pip install arrow
):
import arrow
start = arrow.get('2011-12-25')
end = arrow.get('2012-01-21')
weeks = list(arrow.Arrow.span_range('week', start, end))
result looks like this:
>> from pprint import pprint
>> pprint(weeks[1:])
[(<Arrow [2011-12-19T00:00:00+00:00]>,
<Arrow [2011-12-25T23:59:59.999999+00:00]>),
(<Arrow [2011-12-26T00:00:00+00:00]>,
<Arrow [2012-01-01T23:59:59.999999+00:00]>),
(<Arrow [2012-01-02T00:00:00+00:00]>,
<Arrow [2012-01-08T23:59:59.999999+00:00]>),
(<Arrow [2012-01-09T00:00:00+00:00]>,
<Arrow [2012-01-15T23:59:59.999999+00:00]>),
(<Arrow [2012-01-16T00:00:00+00:00]>,
<Arrow [2012-01-22T23:59:59.999999+00:00]>)]
from there you can change the output to match the year and week number.