Created
October 21, 2020 10:46
-
-
Save bastelflp/dbfa81fdadb4cb10632ca25bca73ff38 to your computer and use it in GitHub Desktop.
Generate dates with calender week
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
# -*- coding: utf-8 -*- | |
# Generate dates | |
# tags: py38 | |
from datetime import date, timedelta | |
import locale | |
locale.setlocale(locale.LC_ALL, 'de_DE.utf8') # set locale for weekday abbreviation | |
# define time range | |
start = date(2020, 10, 1) | |
end = date(2020, 12, 31) | |
# print dates with calender week | |
for counter in range((end - start).days + 1): | |
date_tmp = start + timedelta(days=counter) | |
if date_tmp.isocalendar()[2] == 1: # monday | |
print('CW {}'.format(date_tmp.isocalendar()[1])) # calender week | |
print('* {}: '.format(date_tmp.strftime('%Y-%m-%d (%a)'))) # day |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment