Skip to content

Instantly share code, notes, and snippets.

@kkappel
Last active June 1, 2017 10:03
Show Gist options
  • Select an option

  • Save kkappel/9da44054e9720ad97580ed5bf441bdfd to your computer and use it in GitHub Desktop.

Select an option

Save kkappel/9da44054e9720ad97580ed5bf441bdfd to your computer and use it in GitHub Desktop.
def GetWeek(week_nr, year):
'''
Get start datetime and end datetime of calender week.
Beginning with Monday, ending with Sunday.
Needed for SQL-Queries.
'''
montag = str(week_nr) + "-" + str(year) + '-1'
monday = datetime.strptime(montag, '%W-%Y-%w')
sonntag = str(week_nr) + "-" + str(year) + '-0'
tsunday = datetime.strptime(sonntag, '%W-%Y-%w')
sunday = tsunday + timedelta(days=1)
return (monday, sunday)
@kkappel
Copy link
Author

kkappel commented Jun 1, 2017

Python Function to get start datetime and end datetime of calender week. Beginning with Monday, ending with Sunday. Needed for SQL-Queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment