views:

64

answers:

2

How to increment the day in datetime? In python.

for i in xrange(1,5)
    date=datetime.datetime(2003,8,i,12,4,5)
    print date

But i need pass through years? Any ideas? Should be easyier way....

+5  A: 
date=datetime.datetime(2003,8,1,12,4,5)
for i in range(5): 
    date += datetime.timedelta(days=1)
    print(date) 
unutbu
That what i need! Thanks!
Pol
@Pol, remember to accept your answers...
Wayne Werner
+3  A: 

Incrementing date can be done using timedelta objects

import datetime

datetime.datetime.now() + datatime.timedelta(days=1)

Look up timedelta objects in the python docs: http://docs.python.org/library/datetime.html

Piotr Duda