Skip to content

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

@maticsusteric

Description

@maticsusteric

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirstdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy