Python Getting Yesterday's Date
The following code obtains yesterday's date by importing the datetime module:
Filename : test.py
author by : www.runoob.com
Import the datetime module
import
datetime
def
getYesterday
(
)
:
today
=
datetime
.
date
.
today
(
)
oneday
=
datetime
.
timedelta
(
days
=
1
)
yesterday
=
today
oneday
return
yesterday
Output
(
getYesterday
(
)
)
The output of the code above is:
2015-06-10
The above example outputs that yesterday's date was June 10, 2015.
Python3 Examples