Skip to content

Instantly share code, notes, and snippets.

@lucascheung
Created April 8, 2020 14:46
Show Gist options
  • Save lucascheung/71625cc2ccf439eb38eac93332ab12b6 to your computer and use it in GitHub Desktop.
Save lucascheung/71625cc2ccf439eb38eac93332ab12b6 to your computer and use it in GitHub Desktop.
get dates for the last x days.
from datetime import datetime, timedelta
def last_x_days(days):
"""
INPUT: int, date range, number of days
OUTPUT: dict, of the date range
"""
t = datetime.today()
y = t - timedelta(days=1)
m = y - timedelta(days=days)
y_day = y.strftime("%Y%m%d")
m_day = m.strftime("%Y%m%d")
date_range = {
'min': m_day,
'max': y_day
}
return date_range
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment