I want to create a list with 6-hour intervals from 05:00 on October 29, 2020 to 00:00 on November 1, 2020.
from datetime import datetime, timedelta
def perdate(start, end, delta):
current = start
while current < end:
yield current
current += delta
for result in perdate(datetime(2020, 10, 29, 5,0,0), datetime(2020, 11, 1, 0,0,0), timedelta(hours=6)):
print (result)
2020-10-29 05:00:00
2020-10-29 11:00:00
2020-10-29 17:00:00
2020-10-29 23:00:00
2020-10-30 05:00:00
2020-10-30 11:00:00
2020-10-30 17:00:00
2020-10-30 23:00:00
2020-10-31 05:00:00
2020-10-31 11:00:00
2020-10-31 17:00:00
2020-10-31 23:00:00
Recommended Posts