How to increment date by week?
Tim Chase
python.list at tim.thechases.com
Tue Jun 4 17:50:03 EDT 2013
On 2013-06-04 14:31, PieGuy wrote:
> Starting on any day/date, I would like to create a one year
> list, by week (start date could be any day of week). Having a
> numerical week index in front of date, ie 1-52, would be a bonus.
> ie, 1. 6/4/2013 2. 6/11/2013 3. 6/18/2013....etc to # 52.
import datetime
start = datetime.date.today()
for i in range(53):
dt = start + datetime.timedelta(days=7*i)
result = "%i. %s" % (
i+1,
dt.strftime('%m/%d/%Y')
)
do_something_with(result)
-tkc
More information about the Python-list
mailing list