top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to increment date by week Iin python. ..

+2 votes

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

posted Jun 4, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote
Best answer

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)

answer Jun 4, 2013 by anonymous
0 votes

import datetime
start =
for i in range(53):
dt = start + datetime.timedelta(days=7*i)
result = "%i. %s" % (

answer Jun 4, 2013 by anonymous
Similar Questions
+2 votes

I'm a relative newbie to python, and this NG, but it's certainly growing on me.

One thing I'm missing is the increment/decrement operator from C, ie x++, and its ilk. Likewise x += y.

Is there any way of doing this in Python?

+2 votes

I have python-django installed on ubuntu installed on top of virtual Box. Also I have apache2 installed in the same way. When i visit the page hoisted by Apache2 from my Windows Host machine it worked.
But When i am doing the same for Django pages it's not opening up in Web browser from Host machine.
In the virtual box I am using bridged adapter and Eth0.

Please Help me to sort out this problem

0 votes

For testing purposes I want my code to raise a socket "connection reset by peer" error, so that I can test how I handle it, but I am not sure how to raise the error.

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.