Created
October 25, 2022 16:09
-
-
Save pcolazurdo/92b652f12cf93eed06992ad9be06390b to your computer and use it in GitHub Desktop.
Get specific dates using Python
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 | |
# Every day of the week (starting from tomorrow) for the past 50 weeks | |
now = datetime.now() + timedelta(days=1) | |
for i in range (50): | |
delta = timedelta(days=7*i) | |
print ('"{}"'.format((now-delta).strftime("%b %-d, %Y"))) | |
# Every first Monday of the year | |
# Change weekday() to weekday (7) to get first Sunday | |
for i in range (12,1,-1): | |
seventhday = datetime(2022, int(i), 7) | |
offset = -seventhday.weekday() #weekday = 0 means monday | |
now2 = seventhday+timedelta(offset) | |
print ('"{}"'.format(now2.strftime("%b %-d, %Y"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment