How to increment date by week?
Carlos Nepomuceno
carlosnepomuceno at outlook.com
Tue Jun 4 18:52:01 EDT 2013
> Date: Tue, 4 Jun 2013 14:31:07 -0700
> Subject: How to increment date by week?
> From: r90230 at gmail.com
> To: python-list at python.org
>
> 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.
>
> And to save that result to a file.
> Moving from 2.7 to 3.3
> TIA
YAS:
import datetime
today = datetime.datetime.today()
week = datetime.timedelta(weeks=1)
f=open('output.txt','w')
for i in range(52):
f.write((today+i*week).strftime(str(i+1)+'. %Y-%m-%d\n'))
f.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130605/0e296121/attachment.html>
More information about the Python-list
mailing list