date_range_generator

Generator Date Range

1
def date_range_generator(StartDate: str, EndDate: str, Format: str = '%Y/%m/%d'):
2
"""
3
Generate list of date between StartDate and EndDate.
4
Ex:
5
StartDate = '2018/11/28'
6
EndDate = '2018/12/02'
7
Result:
8
['2018/11/28', '2018/11/29', '2018/11/30',
9
'2018/12/01', '2018/12/02']
10
"""
11
start = datetime.datetime.strptime(StartDate, '%Y/%m/%d')
12
end = datetime.datetime.strptime(EndDate, '%Y/%m/%d')
13
14
date_generated = [
15
start + datetime.timedelta(days=x) for x in range(0, (end-start).days + 1)]
16
return [d.strftime(Format) for d in date_generated]
Copied!
Last modified 1yr ago
Copy link