Custom Search

Friday, March 26, 2010

How find previous or past month and year in python

How find previous or past month and year in python
----------------------------------
today = datetime.date.today()
past_date = today - datetime.timedelta(today.day)
print "past_date", past_date
---------------------------------
today = datetime.date.today()
lastmonth = today - datetime.timedelta(today.day)
print "last_month", lastmonth

---------------------------------
today = datetime.date.today()
lastmonth = today - datetime.timedelta(today.day + 1)
print "last_month", lastmonth
----------------------------------

No comments:

Post a Comment