calculate with date
Robert Kern
rkern at ucsd.edu
Tue Feb 15 03:08:12 EST 2005
Detlef Jockheck wrote:
> Hi,
>
> I have a date-string given in format "dd.mm.yyyy". Now I would like to
> add 100 days. How can this be solved in python?
import datetime
def add100days(datestring):
day, month, year = [int(x) for x in datestring.split('.')]
date0 = datetime.date(year, month, day)
date1 = date0 + datetime.timedelta(days=100)
newdatestring = '%.2d.%.2d.%.4d' % (date1.day, date1.month,
date1.year)
return newdatestring
You may want to do the details differently, but datetime is the module
that you want to use.
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the Python-list
mailing list