I am trying to get the date of the previous month with python. Here is what i\'ve tried:
str( time.strftime(\'%Y\') ) + str( int(time.strftime(\'%m\'))-1 )
<
from datetime import date, timedelta
first_day_of_current_month = date.today().replace(day=1)
last_day_of_previous_month = first_day_of_current_month - timedelta(days=1)
print "Previous month:", last_day_of_previous_month.month
Or:
from datetime import date, timedelta
prev = date.today().replace(day=1) - timedelta(days=1)
print prev.month