Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46971 > unrolled thread

How to increment date by week?

Started byPieGuy <r90230@gmail.com>
First post2013-06-04 14:31 -0700
Last post2013-06-05 09:39 -0700
Articles 9 — 8 participants

Back to article view | Back to comp.lang.python


Contents

  How to increment date by week? PieGuy <r90230@gmail.com> - 2013-06-04 14:31 -0700
    Re: How to increment date by week? Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-04 22:44 +0100
    Re: How to increment date by week? Tim Chase <python.list@tim.thechases.com> - 2013-06-04 16:50 -0500
    Re: How to increment date by week? John Gordon <gordon@panix.com> - 2013-06-04 21:48 +0000
    Re: How to increment date by week? Giorgos Tzampanakis <giorgos.tzampanakis@gmail.com> - 2013-06-04 21:47 +0000
    RE: How to increment date by week? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-05 01:52 +0300
    Re: How to increment date by week? Skip Montanaro <skip@pobox.com> - 2013-06-04 20:17 -0500
    Re: How to increment date by week? steve.ferg.bitbucket@gmail.com - 2013-06-04 20:43 -0700
    Re: How to increment date by week? PieGuy <r90230@gmail.com> - 2013-06-05 09:39 -0700

#46971 — How to increment date by week?

FromPieGuy <r90230@gmail.com>
Date2013-06-04 14:31 -0700
SubjectHow to increment date by week?
Message-ID<b07dac48-1479-42cc-908c-21a3b2e14198@googlegroups.com>
   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

[toc] | [next] | [standalone]


#46972

FromJoshua Landau <joshua.landau.ws@gmail.com>
Date2013-06-04 22:44 +0100
Message-ID<mailman.2683.1370382334.3114.python-list@python.org>
In reply to#46971
On 4 June 2013 22:31, PieGuy <r90230@gmail.com> wrote:
>    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.

[toc] | [prev] | [next] | [standalone]


#46974

FromTim Chase <python.list@tim.thechases.com>
Date2013-06-04 16:50 -0500
Message-ID<mailman.2684.1370382496.3114.python-list@python.org>
In reply to#46971
On 2013-06-04 14:31, PieGuy wrote:
>    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



[toc] | [prev] | [next] | [standalone]


#46975

FromJohn Gordon <gordon@panix.com>
Date2013-06-04 21:48 +0000
Message-ID<kolnc6$l1h$1@reader1.panix.com>
In reply to#46971
In <b07dac48-1479-42cc-908c-21a3b2e14198@googlegroups.com> PieGuy <r90230@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@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#46977

FromGiorgos Tzampanakis <giorgos.tzampanakis@gmail.com>
Date2013-06-04 21:47 +0000
Message-ID<slrnkqsob6.674.giorgos.tzampanakis@brilliance.eternal-september.org>
In reply to#46971
On 2013-06-04, PieGuy wrote:

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

-- 
Real (i.e. statistical) tennis and snooker player rankings and ratings:
http://www.statsfair.com/ 

[toc] | [prev] | [next] | [standalone]


#46980

FromCarlos Nepomuceno <carlosnepomuceno@outlook.com>
Date2013-06-05 01:52 +0300
Message-ID<mailman.2689.1370386330.3114.python-list@python.org>
In reply to#46971

[Multipart message — attachments visible in raw view] — view raw

> Date: Tue, 4 Jun 2013 14:31:07 -0700
> Subject: How to increment date by week?
> From: r90230@gmail.com
> To: python-list@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()

 		 	   		  

[toc] | [prev] | [next] | [standalone]


#46990

FromSkip Montanaro <skip@pobox.com>
Date2013-06-04 20:17 -0500
Message-ID<mailman.2697.1370395040.3114.python-list@python.org>
In reply to#46971
Check out the rrule module in the python-dateutil package:

http://labix.org/python-dateutil
https://pypi.python.org/pypi/python-dateutil

Skip

[toc] | [prev] | [next] | [standalone]


#46999

Fromsteve.ferg.bitbucket@gmail.com
Date2013-06-04 20:43 -0700
Message-ID<673d2f2c-4051-4b15-a262-eeba1748d0d9@googlegroups.com>
In reply to#46971
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)

[toc] | [prev] | [next] | [standalone]


#47110

FromPieGuy <r90230@gmail.com>
Date2013-06-05 09:39 -0700
Message-ID<dba0e3a5-b635-42b9-9e76-8cdcfec408ce@googlegroups.com>
In reply to#46971
On Tuesday, June 4, 2013 2:31:07 PM UTC-7, PieGuy wrote:
> 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web