Some things

Better living through biologically-inspired optimization

Python Date Arithmetic Rules!

I started getting upset that I might have to implement annoying calendrical arithmetic stuff for my program, but it's already been taken care of for me! Praise Bob! Observe:

>>> import datetime
>>> d=datetime.timedelta(days=1)
>>> today=datetime.date.today()
>>> today
datetime.date(2006, 3, 23)
>>> today += d # increment a date by one day
>>> today
datetime.date(2006, 3, 24)

It also knows about when months end and begin.

>>> m1=datetime.date(2006,3,1)
>>> m1-=d
>>> m1
datetime.date(2006, 2, 28)

That is so cool!

The Python docs have more info if you want.

Add a comment

you're not logged in