Skip to content

Instantly share code, notes, and snippets.

@rmondragon
Created August 30, 2018 15:56
Show Gist options
  • Save rmondragon/06b7eda15cdcb63833a051bf516bcbd8 to your computer and use it in GitHub Desktop.
Save rmondragon/06b7eda15cdcb63833a051bf516bcbd8 to your computer and use it in GitHub Desktop.
Get todays start date from in UTC for ET (EDT or EST)
date = "2018-08-30"
year, month, day = date.split('-')
utc = pytz.utc
eastern = timezone('US/Eastern')
# fmt = '%Y-%m-%d %H:%M:%S %Z%z' # returns 2018-08-29 20:00:00 EDT-0400
fmt = '%Y-%m-%dT%H:%M:%SZ'
utc_dt = datetime(year=int(year), month=int(month), day=int(day), hour=0, minute=0, second=0, tzinfo=utc)
loc_dt = utc_dt.astimezone(eastern)
start_date = loc_dt.strftime(fmt) #2018-08-29T20:00:00Z
utc_dt = datetime(year=int(year), month=int(month), day=int(day), hour=23, minute=59, second=59, tzinfo=utc)
loc_dt = utc_dt.astimezone(eastern)
end_date = loc_dt.strftime(fmt) #2018-08-30T19:59:59Z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment