Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Printing list of dates starting today

Reply
Thread Tools

Printing list of dates starting today

 
 
Luka Djigas
Guest
Posts: n/a
 
      09-01-2008
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
 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      09-01-2008
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>

 
Reply With Quote
 
 
 
 
Ari Makela
Guest
Posts: n/a
 
      09-01-2008
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 -
http://www.velocityreviews.com/forums/(E-Mail Removed) a single chair waiting
http://arska.org/hauva/ for someone yet to come
-- Arima Akito
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui C++ 0 04-27-2009 12:51 PM
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui C Programming 0 04-27-2009 12:51 PM
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui Python 0 04-27-2009 12:46 PM
Dates dates dates dates... SQL and ASP.NET David Lozzi ASP .Net 1 09-30-2005 02:18 PM
Dates! Dates! Dates! PW ASP General 4 08-09-2004 04:42 PM



Advertisments