Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2534,8 +2534,8 @@ requires, and these work on all supported platforms.
| ``%d`` | Day of the month as a | 01, 02, ..., 31 | \(9) |
| | zero-padded decimal number. | | |
+-----------+--------------------------------+------------------------+-------+
| ``%D`` | Equivalent to ``%m/%d/%y``. | 11/10/2025 | \(9), |
| | | | \(0) |
| ``%D`` | Equivalent to ``%m/%d/%y``. | 11/28/2025 | \(9) |
| | | | |
+-----------+--------------------------------+------------------------+-------+
| ``%e`` | The day of the month as a | ␣1, ␣2, ..., 31 | |
| | space-padded decimal number. | | |
Expand Down Expand Up @@ -2676,7 +2676,7 @@ differences between platforms in handling of unsupported format specifiers.
``%:z`` was added for :meth:`~.datetime.strftime`.

.. versionadded:: 3.15
``%:z`` and ``%F`` were added for :meth:`~.datetime.strptime`.
``%:z``, ``%F``, and ``%D`` were added for :meth:`~.datetime.strptime`.

Technical Detail
^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions Lib/_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ def __init__(self, locale_time=None):
base.__setitem__('X', self.pattern(self.locale_time.LC_time))
base.__setitem__('x', self.pattern(self.locale_time.LC_date))
base.__setitem__('c', self.pattern(self.locale_time.LC_date_time))
base.__setitem__('D', self.pattern('%m/%d/%Y'))
Comment thread
jyalim marked this conversation as resolved.
Outdated

def __seqToRE(self, to_convert, directive, altregex=None):
"""Convert a list to a regex string for matching a directive.
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,13 @@ def test_strptime_F_format(self):
self.theclass.strptime(test_date, "%Y-%m-%d")
)

def test_strptime_D_format(self):
test_date = "11/28/2025"
self.assertEqual(
self.theclass.strptime(test_date, "%D"),
self.theclass.strptime(test_date, "%m/%d/%Y")
)


#############################################################################
# datetime tests
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,13 @@ def test_strptime_T_format(self):
time.strptime(test_time, "%H:%M:%S")
)

def test_strptime_D_format(self):
test_date = "11/28/2025"
self.assertEqual(
time.strptime(test_date, "%D"),
time.strptime(test_date, "%m/%d/%Y")
)

class Strptime12AMPMTests(unittest.TestCase):
"""Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``'%D'`` support to :meth:`~datetime.datetime.strptime`.
Loading