Skip to content

Instantly share code, notes, and snippets.

@catichenor
Last active January 17, 2017 22:31
Show Gist options
  • Select an option

  • Save catichenor/a56609784ed33bed1ac312742deec48a to your computer and use it in GitHub Desktop.

Select an option

Save catichenor/a56609784ed33bed1ac312742deec48a to your computer and use it in GitHub Desktop.
Print out the date range for the current business week in Python.
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