Question

Let say that I have this code:

import sys
from datetime import datetime

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]
Was it helpful?

Solution

range(startDate.year, endDate.year+1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top