Formatting "yesterday's" date in python Formatting "yesterday's" date in python python python

Formatting "yesterday's" date in python


Use datetime.timedelta()

>>> from datetime import date, timedelta>>> yesterday = date.today() - timedelta(days=1)>>> yesterday.strftime('%m%d%y')'110909'


from datetime import datetime, timedeltayesterday = datetime.now() - timedelta(days=1)yesterday.strftime('%m%d%y')


This should do what you want:

import datetimeyesterday = datetime.datetime.now() - datetime.timedelta(days = 1)print yesterday.strftime("%m%d%y")


matomo