timedelta 1

timedelta

>>> import datetime
>>> d1 = datetime.date.today()
>>> from dateutil.relativedelta import relativedelta
>>> d1 + relativedelta(months=1)
datetime.date(2012, 4, 8)

>>> d2 = datetime.date(year=2012,month=1,day=31)
>>> d2 + relativedelta(months=1)
datetime.date(2012, 2, 29)

Here is what the above code is Doing:
1. Importing the datetime module
2. Creating a date object for today’s date
3. Importing the relativedelta function from the dateutil module
4. Adding one month to the date object d1
5. Creating a date object for January 31, 2012
6. Adding one month to the date object d2

Similar Posts