Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.