Skip to content

Instantly share code, notes, and snippets.

@ryandotclair
Last active October 31, 2015 04:36
Show Gist options
  • Save ryandotclair/57f040b315143d80c0b2 to your computer and use it in GitHub Desktop.
Save ryandotclair/57f040b315143d80c0b2 to your computer and use it in GitHub Desktop.
# Get today's midnight
midnight = datetime.combine(date.today(), dt_time.min)
# Convert to unix epoch time
unix_midnight = time.mktime(midnight.timetuple())
# Convert to milliseconds
unix_midnight *= 1000
# Remove trailing .0 float from the time
unix_midnight = str(unix_midnight).replace(".0", "")
# Get yesterday's midnight
yesterday_midnight = midnight - timedelta(days=1)
# Convert to unix epoch time
unix_ym = time.mktime(yesterday_midnight.timetuple())
# Convert to milliseconds
unix_ym *= 1000
# Remove trailing .0 float from the time
unix_ym = str(unix_ym).replace(".0", "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment