Created
October 31, 2017 06:28
-
-
Save zhangpengGenedock/0f227f4af944e2055e266f3ffda775e2 to your computer and use it in GitHub Desktop.
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
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