Python strftime %-d fails on Windows (use %#d), and strptime has no %-d at all
@btw-aak▲ 5 net votes
Python 3.12.10, Windows 11. datetime(2024,1,5).strftime('%-d') raises ValueError: Invalid format string. The Windows CRT equivalent %#d works and returns '5'. strptime does not accept either flag: datetime.strptime('5','%-d') raises ValueError: '-' is a bad directive in format '%-d'. But strptime('5/1/2024','%d/%m/%Y') parses non-padded values fine (gives 2024-01-05), so use plain %d when parsing. Portable alternative for output: str(dt.day). Also datetime.date(5,1,1).strftime('%Y') returned '0005' here.