Latest web development tutorials

Get Python Yesterday Date

Document Object Reference Examples Python3

The following code by importing datetime module to get yesterday's date:

# Filename : test.py
# author by : www.w3big.com

# 引入 datetime 模块
import datetime
def getYesterday(): 
	today=datetime.date.today() 
	oneday=datetime.timedelta(days=1) 
	yesterday=today-oneday  
	return yesterday

# 输出
print(getYesterday())

Execute the above code output results:

2015-06-10

Examples of the above output meaning yesterday's date is June 10, 2015.

Document Object Reference Examples Python3