Created
September 1, 2022 17:53
-
-
Save tuttle/750221230ac4f3b5e9538f44d9fa7a59 to your computer and use it in GitHub Desktop.
This file contains 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
import datetime | |
dates = ['20220902', '20220909', '20220916', '20220923', '20220930', | |
'20221007', '20221014', '20221021', '20221118', '20221216', | |
'20230120', '20230317', '20230421', '20230616', '20230915', | |
'20240119', '20240315', '20240621'] | |
# [ datetime.date(2022, 9, 2), datetime.date(2022, 9, 9), datetime.date(2022, 9, 16), ... ] | |
dates = [datetime.datetime.strptime(d, '%Y%m%d').date() for d in dates] | |
pivot = datetime.date.today() + datetime.timedelta(days=16) | |
closest_date = min(dates, key=lambda item: abs(item-pivot)) | |
print( | |
closest_date.strftime('%Y%m%d') | |
) | |
# '20220916' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment