Adam Johnson
Read post

Python: fix ValueError: day of month directive '%d' may not be used without a year directive

Python 3.15 raises a ValueError whenever strptime() uses the %d (day of month) directive without a year directive, breaking code that previously parsed month-day strings without a year. This behavior was deprecated in Python 3.13 with a DeprecationWarning, and the root cause is that strptime() defaulted to 1900 (a non-leap year), making February 29th unparseable. The fix is to append a leap year (e.g., 2000) to both the input string and the format string, ensuring all dates including Feb 29 parse correctly across all Python versions.

    #python
Jul 29•3m read time•From adamj.eu
Post cover image
Table of contents
The fixFin
443 Impressions
Adam Johnson's image
Adam Johnson

AdamJ's platform covers topics related to software development, technology trends, and coding tutor...

54 Followers

•

444 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard