Easy Tutorial
❮ Python Func Number Radians Python Func Str ❯

Python Get Yesterday's Date

Python3 Examples

The following code imports the datetime module to get yesterday's date:

# Filename : test.py
# author by : www.tutorialpro.org

# Import datetime module
import datetime
def getYesterday(): 
    today = datetime.date.today() 
    oneday = datetime.timedelta(days=1) 
    yesterday = today - oneday  
    return yesterday

# Output
print(getYesterday())

Executing the above code outputs:

2015-06-10

The output example indicates that yesterday's date was June 10, 2015.

Python3 Examples

❮ Python Func Number Radians Python Func Str ❯