Created
August 12, 2011 16:01
-
-
Save cosmin/1142361 to your computer and use it in GitHub Desktop.
range equivalent for datetime
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_or_end, end=None, step=datetime.timedelta(1)): | |
"daterange([start,] stop[, step]) -> list of dates" | |
if end == None: | |
end = start_or_end | |
start = datetime.date.today() | |
current = start | |
while current < end: | |
yield current | |
current = current + step |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment