Oct-01-2020, 10:05 AM
Hi,
I want to make list of dates from now back to n days (for example 2 days) with time interval 12hrs.
I use the bewlow code, but its giving me empty.
my_list of dates:
[2020-09-29 18:10:10 2020-09-30 06:10:10 2020-09-30 18:10:10 2020-10-01 06:10:10 2020-10-01 18:10:10]
I want to make list of dates from now back to n days (for example 2 days) with time interval 12hrs.
I use the bewlow code, but its giving me empty.
from datetime import date, datetime, timedelta def datetime_range(start, end, delta): current = start print(current) if not isinstance(delta, timedelta): delta = timedelta(delta) while current < end: yield current current += delta interval=12 #12hrs n_days=2 start = date.today() end=start_dt-timedelta(days=n_days) dates_list =[] for dt in datetime_range(start, end,interval): dt_m = (dt-timedelata(hours=12)).strftime("%Y-%m-%d %H:%M:%S") dates_list.append(dt_m)my desired output is: for example time now is 2020-10-01 18:10:10
my_list of dates:
[2020-09-29 18:10:10 2020-09-30 06:10:10 2020-09-30 18:10:10 2020-10-01 06:10:10 2020-10-01 18:10:10]