Created
December 30, 2012 22:26
-
-
Save rooty/4415665 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def daterange(start, stop, step=datetime.timedelta(days=1), inclusive=True): | |
# inclusive=False to behave like range by default | |
if step.days > 0: | |
while start < stop: | |
yield start | |
start = start + step | |
elif step.days < 0: | |
while start > stop: | |
yield start | |
start = start + step | |
if inclusive and start == stop: | |
yield start | |
Как юзать ? Вот например так: | |
from datetime import timedelta,date | |
end_date = date.toady() | |
start_date = date.today()-timedelta(days=365) | |
dates = [x for x in daterange(start_date, | |
end_date, | |
step=timedelta(weeks=1), | |
inclusive=True)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment