How to increment date by week?

P

PieGuy

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
 
J

Joshua Landau

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

What have you tried? What are you stuck on? We're not here to do your
work for you.

See http://docs.python.org/3/library/datetime.html for where to get started.
 
G

Giorgos Tzampanakis

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.

date2 = date1 + datetime.timedelta(7)
 
J

John Gordon

In said:
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)
 
T

Tim Chase

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
 
C

Carlos Nepomuceno

Date: Tue, 4 Jun 2013 14:31:07 -0700
Subject: How to increment date by week?
From: (e-mail address removed)
To: (e-mail address removed)

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()
 
S

steve.ferg.bitbucket

pyfdate -- http://www.ferg.org/pyfdate/

from pyfdate import Time
w = Time(2013,1,2) # start with January 2, 2013, just for example

# print the ISO weeknumber and date for 52 weeks
# date looks like this: October 31, 2005
for i in range(52):
w = w.plus(weeks=1)
print (w.weeknumber, w.d)
 
P

PieGuy

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.

Thank you Python Community! I am almost 75, moving from 2.7 to 3.n, just started with Linux Ubuntu, and using WING IDE but my 3 Python books do not offer the clarity of this group. Again, thanks to all who responded.

And to save that result to a file.

Moving from 2.7 to 3.3

TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top