>>> from datetime import datetime, timedelta >>> datetime.strftime(datetime.now() - timedelta(1), '%Y-%m-%d') '2015-05-26'
Here is what the above code is Doing:
1. Importing the datetime module.
2. Creating a datetime object for the current time.
3. Subtracting a timedelta object from the current time.
4. Converting the resulting datetime object to a string.
5. Printing the string.
The output of the code is:
2015-05-26