Which fix removes the bug?
from datetime import datetime
d = datetime.strptime('2026-10-11', '%Y-%d-%m')
print(d.month) # expected 10
- Use the format
'%Y-%m-%d' - Use the format
'%y-%m-%d' - Call
d.dayinstead here - Parse it with
int()first
The format swaps day and month, so the date silently parses as 10 November.
Play Problem Solving ▸