Question: I want to calculate 6 month before date in python.So is there any problem occurs at dates (example 31 august).Can we solve this problem using timedelta() function.can we pass months like *date=now - timedelta(days=days)* instead of argument days.

Answer: 
If you are only interested in what the month was 6 months ago then try this:

```
import datetime

month = datetime.datetime.now().month - 6
if month < 1:
    month = 12 + month  # At this point month is 0 or a negative number so we add

```
Following function should work fine for both month add and month substract.

```
import datetime
import calendar

def add_months(sourcedate, months):
     month = sourcedate.month - 1 + months
     year = sourcedate.year + month / 12
     month = month % 12 + 1
     day = min(sourcedate.day,calendar.monthrange(year,month)[1])
     return datetime.date(year,month,day)

#Example: Get today    
dateToday = datetime.date.today()

#Substract 6 month from Today
print add_months(dateToday ,-6)

```