Skip to content

Instantly share code, notes, and snippets.

@wang-zhijun
Last active March 16, 2016 13:35
Show Gist options
  • Save wang-zhijun/7819476 to your computer and use it in GitHub Desktop.
Save wang-zhijun/7819476 to your computer and use it in GitHub Desktop.
Pythonで直近の前の金曜日の日付を調べる
#!/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