Created
April 2, 2012 21:27
-
-
Save roopeshvaddepally/2287345 to your computer and use it in GitHub Desktop.
Python Date Range
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 | |
from time import mktime | |
def convert_date_to_datetime(date_object): | |
date_tuple = date_object.timetuple() | |
date_timestamp = mktime(date_tuple) | |
return datetime.datetime.fromtimestamp(date_timestamp) | |
def date_range(how_many=7): | |
for x in range(0, how_many): | |
some_date = datetime.datetime.today() - datetime.timedelta(days=x) | |
some_datetime = convert_date_to_datetime(some_date.date()) | |
yield some_datetime | |
def pick_two_dates(how_many=7): | |
a = b = convert_date_to_datetime(datetime.datetime.now().date()) | |
for each_date in date_range(how_many): | |
b = a | |
a = each_date | |
if a == b: | |
continue | |
yield b, a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment