Guest User

Untitled

a guest
Dec 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. def daterange(date1, date2, freq, multi, dt_format):
  2. start = datetime.strptime(date1, "%Y-%m-%d")
  3. end = datetime.strptime(date2, "%Y-%m-%d")
  4. while start < end:
  5. yield start, start + timedelta(**{freq: multi})
  6. start = start + timedelta(**{freq: multi})
  7.  
  8. for from_dt, to_dt in daterange('2018-01-01', '2018-02-01', 'hours', 1, "%Y-%m-%dT%H:%M:%S"):
  9. print("Range:",from_dt,"-",to_dt)
Add Comment
Please, Sign In to add comment