Skip to content

Instantly share code, notes, and snippets.

@zhangpengGenedock
Created October 31, 2017 06:28
Show Gist options
  • Save zhangpengGenedock/0f227f4af944e2055e266f3ffda775e2 to your computer and use it in GitHub Desktop.
Save zhangpengGenedock/0f227f4af944e2055e266f3ffda775e2 to your computer and use it in GitHub Desktop.
up vote
67
down vote
Use the datetime module.
This will yield start and end of week (from Monday to Sunday):
from datetime import datetime, timedelta
day = '12/Oct/2013'
dt = datetime.strptime(day, '%d/%b/%Y')
start = dt - timedelta(days=dt.weekday())
end = start + timedelta(days=6)
print(start)
print(end)
EDIT:
print(start.strftime('%d/%b/%Y'))
print(end.strftime('%d/%b/%Y'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment