How to increment date by week?

John Gordon gordon at panix.com
Tue Jun 4 17:48:54 EDT 2013


In <b07dac48-1479-42cc-908c-21a3b2e14198 at googlegroups.com> PieGuy <r90230 at gmail.com> writes:

>    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

from datetime import date, timedelta

the_date = date(year=2013, month=6, day=4)

print "%d. %s" % (1, the_date)

for n in range(2, 53):
    the_date = the_date + timedelta(days=7)
    print "%d. %s" % (n, the_date)

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list