Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all years between two dates in python

Tags:

python

date

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]
like image 634
WebOrCode Avatar asked May 11 '14 07:05

WebOrCode


1 Answers

range(startDate.year, endDate.year+1)
like image 173
Daniel Avatar answered Oct 13 '22 21:10

Daniel