How to modify a time with datetime.timedelta and then format it with datetime.date.strftime?

I can find the date of next Sunday (or today if today is Sunday) just fine using timedelta with the line:
print(datetime.date.today() + datetime.timedelta(7 - int(time.strftime("%u"))))
And I can take today's date and format it the way I want just fine using strftime with the line:
print(datetime.date.today().strftime("%d.%m.%Y"))
But I can't for the life of me figure out how to get these two to play well together so I can have next Sunday's date in the format I want. The result I get from running these two individually is
2025-05-04
27.04.2025
but I want 05.04.2025. I'm aware I could feed the 2025-05-04 into str() and then format it but that feels clunky. I was hoping to find out how to use strftime in this situation because I'm pretty sure what I'm trying to do is exactly what it's intended for.
Answer
Use strftime to make things pretty for humans, not for computation.
To get next Sunday, use date.Weekday() and to find the correct number of days to add.
from datetime import date, timedelta
today = date.today()
sunday = today + timedelta(days=6-today.weekday())
print(sunday.strftime('%d.%m.%Y'))
https://docs.python.org/3/library/datetime.html#datetime.date.weekday
Return the day of the week as an integer, where Monday is 0 and Sunday is 6. For example, date(2002, 12, 4).weekday() == 2, a Wednesday. See also isoweekday().
Enjoyed this question?
Check out more content on our blog or follow us on social media.
Browse more questions