top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

How to increment date by week Iin python. ..

+2 votes
57 views

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 Google+ Share Button LinkedIn Share Button Multiple Social 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 = 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)

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.


Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.
QUERY HOME
...