Thursday, January 30, 2014

Finding yesterday's date in python




from datetime import date, timedelta
yesterday = date.today() - timedelta(1)
print yesterday #date object
print yesterday.strftime('%Y-%m-%d') #string object in form of yyyy-mm-dd
print yesterday.strftime('%y-%m-%d') #string object in form of yy-mm-dd

Ref: http://docs.python.org/2/library/datetime.html