I have to get the date of the day approximately one month before from today in python.
The resulting string should be of the format yyyy/mm/dd
The date has to be approximate, so things like considering the leap year and all can be avoided (or if easy can be incorporated as well)
I have written the following code for the above problem
from datetime import date
tup=list(date.today().timetuple()[0:3])
if (tup[1]==1):
tup[1]=12
tup[0]-=1
else:
tup[1]-=1
if tup[1]==2:
tup[2]=min(28,tup[2])
else if tup[1] in [4,6,9,11]:
tup[2]=min(30,tup[2])
print '/'.join([str(x) for x in tup])
Is there a more elegant way to solve the above problem??