Created
April 8, 2020 14:46
-
-
Save lucascheung/71625cc2ccf439eb38eac93332ab12b6 to your computer and use it in GitHub Desktop.
get dates for the last x days.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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