Skip to content

Instantly share code, notes, and snippets.

@liladas
Created April 30, 2018 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liladas/45db5eca1cf9947eb32f760ac6fa2f8d to your computer and use it in GitHub Desktop.
Save liladas/45db5eca1cf9947eb32f760ac6fa2f8d to your computer and use it in GitHub Desktop.
Getting previous time windows
#!/usr/bin/env python3
from datetime import datetime, timedelta
current_time = datetime.now()
start_time = current_time.replace(microsecond=0,second=0,minute=0,hour=0)-timedelta(days=1)
end_time = current_time.replace(microsecond=0,second=0,minute=0,hour=0)-timedelta(seconds=1)
print("Getting All Data from Day Prior")
print("Time of invocation:", current_time)
print("Start Time Window :", start_time)
print("End Time Window :", end_time)
start_time = current_time.replace(microsecond=0,second=0,minute=0)-timedelta(hours=1)
end_time = current_time.replace(microsecond=0,second=0,minute=0)-timedelta(seconds=1)
print("Getting All Data from Hour Prior")
print("Time of invocation:", current_time)
print("Start Time Window :", start_time)
print("End Time Window :", end_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment