Created
March 19, 2019 21:16
-
-
Save includeamin/ef8c11df7015f78ecd103f6b62e0807a to your computer and use it in GitHub Desktop.
python datetime some types
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
days = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] | |
today_date = datetime.datetime.today() | |
last30date = today_date - datetime.timedelta(days=30) | |
todayname = today_date.strftime("%A") | |
startweek = "" | |
endweek = "" | |
if todayname == days[0]: | |
startweek = today_date | |
else: | |
index = days.index(todayname) | |
startweek = today_date - datetime.timedelta(days=index) | |
endweek = today_date + datetime.timedelta(days=(len(days)-index)) | |
startOflastweek = startweek - datetime.timedelta(days=6) | |
endOflastweek = startweek - datetime.timedelta(days=1) | |
startOfthisMonth = datetime.datetime(today_date.year, today_date.month, 1) | |
startOfLastMonth = startOfthisMonth - datetime.timedelta(days=30) | |
endOfLastMonth = startOfLastMonth + datetime.timedelta(days=29) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment