Skip to content

Commit 12a77cc

Browse files
Move & reword
1 parent 3179f74 commit 12a77cc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Doc/library/datetime.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,11 +2495,6 @@ These methods accept format codes that can be used to parse and format dates::
24952495
>>> _.strftime('%a %d %b %Y, %I:%M%p')
24962496
'Mon 31 Jan 2022, 11:59PM'
24972497

2498-
The user has to make sure, though, that the input can be parsed in a unambiguous
2499-
way. The string ``2025112`` can be parsed using the format ``%Y%m%d`` as ``2025-1-12``,
2500-
``2025-11-2``, or even ``20251-1-2``. It is necessary to add appropriate separators to
2501-
reliably get results.
2502-
25032498
The following is a list of all the format codes that the 2011 C standard
25042499
requires, and these work on all supported platforms.
25052500

@@ -2694,6 +2689,11 @@ For the :meth:`.datetime.strptime` and :meth:`.date.strptime` class methods,
26942689
the default value is ``1900-01-01T00:00:00.000``: any components not specified
26952690
in the format string will be pulled from the default value.
26962691

2692+
.. note::
2693+
Format strings without separators can be ambiguous for parsing. For
2694+
example, ``%Y%m%d`` parses the string ``2026111`` as ``2026-11-01``,
2695+
not ``2026-01-11``. Use separators to ensure the input is parsed as intended.
2696+
26972697
.. note::
26982698
When used to parse partial dates lacking a year, :meth:`.datetime.strptime`
26992699
and :meth:`.date.strptime` will raise when encountering February 29 because

0 commit comments

Comments
 (0)