Skip to content

Commit 36a8301

Browse files
MariattaStanFromIreland
authored andcommitted
gh-124549: Document that strptime() uses the last directive when a time unit is over-specified (GH-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> --------- (cherry picked from commit fd6ed15) Co-authored-by: Mariatta <Mariatta@users.noreply.github.com> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent d920ff9 commit 36a8301

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
@@ -2703,6 +2703,13 @@ in the format string will be pulled from the default value.
27032703
the default year of 1900 is *not* a leap year. Always add a default leap
27042704
year to partial date strings before parsing.
27052705

2706+
.. note::
2707+
If a :meth:`~.datetime.strptime` format string contains more than
2708+
one directive for the same field, for example both ``%Y`` and ``%y``,
2709+
every directive must still match the input, but only the value of the
2710+
last one is used. For example, parsing ``200099`` with ``%Y%y`` gives
2711+
the year 1999. Repeating the same directive, like ``%Y%Y``, raises an error.
2712+
27062713
.. testsetup::
27072714

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

0 commit comments

Comments
 (0)