Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Getting Yesterday's Date

Python Getting Yesterday's Date

Document Object Reference Manual Python3 Examples

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

print

(

getYesterday

(

)

)

The output of the code above is:


2015-06-10

The above example outputs that yesterday's date was June 10, 2015.

Document Object Reference Manual Python3 Examples