Skip to content

Commit fd6ed15

Browse files
gh-124549: Document that strptime() uses the last directive when a time unit is over-specified (#125009)
* Add a note that when over-specifying datetime format, only the last directive gets used. * adjust and reorganize the notes location, fast forward to latest. * Update Doc/library/datetime.rst Co-authored-by: Stan Ulbrych <stan@python.org> --------- Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent f071bac commit fd6ed15

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎Doc/library/datetime.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,13 @@ in the format string will be pulled from the default value.
27452745
the default year of 1900 is *not* a leap year. Always add a default leap
27462746
year to partial date strings before parsing.
27472747

2748+
.. note::
2749+
If a :meth:`~.datetime.strptime` format string contains more than
2750+
one directive for the same field, for example both ``%Y`` and ``%y``,
2751+
every directive must still match the input, but only the value of the
2752+
last one is used. For example, parsing ``200099`` with ``%Y%y`` gives
2753+
the year 1999. Repeating the same directive, like ``%Y%Y``, raises an error.
2754+
27482755
.. testsetup::
27492756

27502757
# doctest seems to turn the warning into an error which makes it

0 commit comments

Comments
 (0)