Last active
January 17, 2017 22:31
-
-
Save catichenor/a56609784ed33bed1ac312742deec48a to your computer and use it in GitHub Desktop.
Print out the date range for the current business week in 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 | |
| today = datetime.now() | |
| date_today = datetime(today.year, today.month, today.day) | |
| day_of_the_week = date_today.weekday() | |
| date_start_delta = timedelta(-(date_today.weekday())) | |
| date_start = date_today + date_start_delta # Result should be Monday of this week. | |
| date_end_delta = timedelta(4) | |
| date_end = date_start + date_end_delta # Result should be Friday of this week. | |
| print 'Work days: {startmonth}-{startday} to {endmonth}-{endday}-{endyear}'.format( | |
| startmonth=date_start.month, startday=date_start.day, | |
| endmonth=date_end.month, endday=date_end.day, endyear=date_end.year) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment