Python Get Yesterday's Date

Document 对象参考手册Python3 Examples

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

# Filename : test.py # author by : www.example.com # Import datetime module import datetime def getYesterday(): today=datetime.date.today() oneday=datetime.timedelta(days=1) yesterday=today-oneday return yesterday # Output print(getYesterday())

The output of the above code is:

2015-06-10

The output of the above example means yesterday's date was June 10, 2015.

Document 对象参考手册Python3 Examples

Other Extensions