Skip to content

Instantly share code, notes, and snippets.

@bpceee
Created June 22, 2014 13:36
Show Gist options
  • Save bpceee/611e2a4757fc06fc1bc9 to your computer and use it in GitHub Desktop.
Save bpceee/611e2a4757fc06fc1bc9 to your computer and use it in GitHub Desktop.
date iteration
#!/usr/bin/env python
# coding=utf-8
from datetime import datetime, timedelta
def daterange(start, stop, step_minutes=1):
current = start
step = timedelta(minutes=step_minutes)
if step_minutes > 0:
while current < stop:
yield current
current += step
elif step_minutes < 0:
while current > stop:
yield current
current += step
else:
raise ValueError("daterange() step_days argument must not be zero")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment