Last active
March 16, 2016 13:35
-
-
Save wang-zhijun/7819476 to your computer and use it in GitHub Desktop.
Pythonで直近の前の金曜日の日付を調べる
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
#!/usr/bin/env python | |
import datetime, calendar | |
def find_last_friday(): | |
# output: 2013-12-06 | |
last_friday = datetime.date.today() | |
# output: 1 day, 0:00:00 | |
one_day = datetime.timedelta(days = 1) | |
# calendar.FRIDAY: 4 | |
while last_friday.weekday() != calendar.FRIDAY: | |
last_friday -= on_day | |
return last_friday.strftime('%Y-%m-%d %A') | |
if __name__ == '__main__': | |
print find_last_friday() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment