获取python中两个日期之间的所有年份

时间:2022-07-08 21:30:44

Let say that I have this code:

假设我有这个代码:

import sys
from datetime import date time

startDate = datetime.strptime(sys.argv[1], '%d.%m.%Y') # e.g. 05.06.2001 DD.MM.YYYY
endDate   = datetime.strptime(sys.argv[2], '%d.%m.%Y') # e.g. 25.05.2005

How to get all the years between these two dates, including start and end year, like

如何获得这两个日期之间的所有年份,包括开始和结束年份

[2001, 2002, 2003, 2004, 2005]

1 个解决方案

#1


13  

range(startDate.year, endDate.year+1)

#1


13  

range(startDate.year, endDate.year+1)