Printing list of dates starting today

Fredrik Lundh fredrik at pythonware.com
Mon Sep 1 17:52:31 CEST 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>




More information about the Python-list mailing list