From 498807188a4fe12d8ab7293e27ecb0fe5db5cc76 Mon Sep 17 00:00:00 2001 From: mariatta Date: Sat, 5 Oct 2024 11:15:49 -0700 Subject: [PATCH] Add a note that when over-specifying datetime format, only the last directive gets used. --- Doc/library/datetime.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst index 64510a77c67c11..7a5f8ae2c95d90 100644 --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -2761,6 +2761,14 @@ Notes: :exc:`DeprecationWarning`. In 3.15 or later we may change this into an error or change the default year to a leap year. See :gh:`70647`. +(11) + When parsing a string using :meth:`~.datetime.strptime`, if more than one + directives of the same time unit were used, only the last directive gets parsed + and applied to the datetime object. For example, if the format string contains + both ``%Y`` and ``%y``, like ``%Y%y``, only the last directive on the string (``%y``) + gets used on the resulting datetime object. + + .. rubric:: Footnotes .. [#] If, that is, we ignore the effects of Relativity