python / python/cpython

Enhancement Proposal: Standardized Support for Non-Zero-Padded Day and Month Formatting in datetime.strftime

Open
#137,165 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

Python's datetime.datetime.strftime supports formatting directives for dates and times, such as %d for zero-padded days and %m for zero-padded months.
While there are platform-specific ways to get non-zero-padded day (%-d on Unix) or month (%-m), these do not work reliably across all platforms.. Particularly between Unix-like systems and Windows.

from datetime import datetime

dt = datetime(2025, 6, 6)

# On Unix:
dt.strftime("%-d. %-m. %Y")  # '6. 6. 2025'

# On Windows:
dt.strftime("%-d. %-m. %Y")  # Raises ValueError

I understand that strftime relies on the underlying C library for formatting, which is probably why this behavior differs between platforms. That said, if it's not practical to change this at the core level, maybe there could be some kind of wrapper or Python-level normalization to make things more consistent across systems.

Currently this requires a workaround such as usage of .format directly on the datetime object.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-138982
  • gh-139002
  • gh-139088
  • gh-145018

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at datetime.datetime.strftime and investigate how its directives depend on the underlying C library on Unix-like systems and Windows. Review the linked PRs before starting; done would mean a decided, consistent approach for non-zero-padded day and month formatting across platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.