Printing list of dates starting today

Discussion in 'Python' started by Luka Djigas, Sep 1, 2008.

  1. Luka Djigas

    Luka Djigas Guest

    Hello everyone,

    please, I need your help. I'm new to python, so I don't know if this
    will seem like a stupid question to some of you ...
    I have a need to write to a file (or just print on screen, that part
    doesn't matter at this point) a list of dates, starting today. For
    example:
    02.09.2008. tue
    03.09.2008. wed
    et cetera

    Is there some intristic function in python which can help me with this
    or do I have to do the calendar calculation by hand ?

    Would appreciate all the help I can get.

    Regards
    Luka Djigas
     
    Luka Djigas, Sep 1, 2008
    #1
    1. Advertising

  2. Luka Djigas wrote:

    > please, I need your help. I'm new to python, so I don't know if this
    > will seem like a stupid question to some of you ...
    > I have a need to write to a file (or just print on screen, that part
    > doesn't matter at this point) a list of dates, starting today. For
    > example:
    >
    > 02.09.2008. tue
    > 03.09.2008. wed
    > et cetera
    >
    > Is there some intristic function in python which can help me with this
    > or do I have to do the calendar calculation by hand ?


    >>> import datetime
    >>> # see: http://docs.python.org/lib/module-datetime.html
    >>> d = datetime.date.today()
    >>> str(d)

    '2008-09-01'
    >>> d.strftime("%d.%m.%Y. %a")

    '01.09.2008. Mon'
    >>> # see http://docs.python.org/lib/module-time.html#l2h-2826
    >>> d.strftime("%d.%m.%Y. %a").lower()

    '01.09.2008. mon'
    >>> for i in range(10):

    .... print d.strftime("%d.%m.%Y. %a").lower()
    .... d += datetime.timedelta(days=1)
    ....
    01.09.2008. mon
    02.09.2008. tue
    03.09.2008. wed
    04.09.2008. thu
    05.09.2008. fri
    06.09.2008. sat
    07.09.2008. sun
    08.09.2008. mon
    09.09.2008. tue
    10.09.2008. wed

    </F>
     
    Fredrik Lundh, Sep 1, 2008
    #2
    1. Advertising

  3. Luka Djigas

    Ari Makela Guest

    On 2008-09-01, Luka Djigas <ldigas@remove_this.gmail.com> wrote:

    > please, I need your help. I'm new to python, so I don't know if this
    > will seem like a stupid question to some of you ...


    There are several ways to do it. Have a look at the documentation
    of modules time and datetime. For this exact problem time is the
    most straighforward one.

    > I have a need to write to a file (or just print on screen, that part
    > doesn't matter at this point) a list of dates, starting today. For
    > example:
    > 02.09.2008. tue
    > 03.09.2008. wed


    0 hauva@laphroaig:~
    $ /usr/bin/python
    Python 2.5.2 (r252:60911, Jul 31 2008, 17:31:22)
    [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import time
    >>> DAY = 60 * 60 * 24
    >>> today = time.time()
    >>> for i in (0, 1, 2, 3):

    .... t = time.gmtime(time.time() + i * DAY)
    .... print time.strftime('%d.%m.%Y, %a', t)
    ....
    01.09.2008, Mon
    02.09.2008, Tue
    03.09.2008, Wed
    04.09.2008, Thu

    --
    Ari Makela late autumn -
    a single chair waiting
    http://arska.org/hauva/ for someone yet to come
    -- Arima Akito
     
    Ari Makela, Sep 1, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    867
    Rob Schieber
    Sep 30, 2005
  2. tshad
    Replies:
    4
    Views:
    30,099
    natty_dread
    Aug 7, 2007
  3. Thomas Stein
    Replies:
    1
    Views:
    863
  4. Replies:
    1
    Views:
    402
  5. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    197
    Mark Schupp
    Aug 9, 2004
Loading...

Share This Page