Given two datetimes (start_date and end_date), I’d like to generate a list of other datetimes between these two dates, the new datetimes being separated by a variable interval. e.g. every 4 days between 2011-10-10 and 2011-12-12 or every 8 hours between now and tomorrow 19p.m.
Maybe something roughly equivalent to the Dateperiod PHP class.
What would be the most efficient way to accomplish this in Python?
Use
datetime.timedelta:Works for both dates and datetime objects. Your second example: