Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python Date Range
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.timedelta(days=x)
some_datetime = convert_date_to_datetime(
yield some_datetime
def pick_two_dates(how_many=7):
a = b = convert_date_to_datetime(
for each_date in date_range(how_many):
b = a
a = each_date
if a == b:
yield b, a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment