get the date for the last day of this week in python

You can use the date and datetime modules in Python to get the date for the last day of the current week. Here's a code snippet that will do the job:

main.py
import datetime

today = datetime.date.today()
last_day_of_week = today + datetime.timedelta(6 - today.weekday())

print(last_day_of_week)
139 chars
7 lines

In the above code, today is the current date, and weekday() returns the day of the week as an integer (0 for Monday, 1 for Tuesday, etc.). So 6 - today.weekday() gives the number of days from today to the end of the week (assuming Sunday is the last day of the week). We add this to today to get the date for the last day of the week. The result is then printed using the print() function.

gistlibby LogSnag