I want to iterate through the dates in for loop. sample ddates : 20170101 20170107
output should be : 20170101 20170102 20170103 20170104 20170105 20170106 20170107
I want to iterate through the dates in for loop. sample ddates : 20170101 20170107
output should be : 20170101 20170102 20170103 20170104 20170105 20170106 20170107
datetime.strptime is what you're looking for
start = 20170101
end = 20170107
dates = []
for i in range(start, end):
dates.append(datetime.strptime(str(i), "%Y%m%d"))
dates will then have:
[datetime.datetime(2017, 1, 1, 0, 0), datetime.datetime(2017, 1, 2, 0, 0), datetime.datetime(2017, 1, 3, 0, 0), datetime.datetime(2017, 1, 4, 0, 0), datetime.datetime(2017, 1, 5, 0, 0), datetime.datetime(2017, 1, 6, 0, 0)]