import datetime
# this will fail
datetime.datetime.strptime('2025-10-26','%F')
# this will succeed
d0 = datetime.datetime.strptime('15:00:00','%T')
print(d0.strftime('%FT%T'))
Example above ('%F', C99+ time.h format token) requires simple fix in the code; requires larger alignment in documentation.
Example Code Patch
To support '%F' in strptime requires adding a single line of code. The example above is fixed with the following line added to the TimeRE class __init__ method in Lib/_strptime.py,
base.__setitem__('F', self.pattern('%Y-%m-%d'))
just like existing code in that method for %T support (https://github.com/python/cpython/blob/main/Lib/_strptime.py#L421)
Documentation
The documentation refers to C89 (https://github.com/python/cpython/blob/main/Doc/library/datetime.rst?plain=1#L2498-L2636) and does not fully document the current level of strptime support.
Final thoughts
A larger discussion should be had on modernizing datetime and fully supporting C99 (ideally newer) time.h format tokens.
Linked PRs
Example above (
'%F', C99+time.hformat token) requires simple fix in the code; requires larger alignment in documentation.Example Code Patch
To support
'%F'instrptimerequires adding a single line of code. The example above is fixed with the following line added to theTimeREclass__init__method inLib/_strptime.py,just like existing code in that method for
%Tsupport (https://github.com/python/cpython/blob/main/Lib/_strptime.py#L421)Documentation
The documentation refers to C89 (https://github.com/python/cpython/blob/main/Doc/library/datetime.rst?plain=1#L2498-L2636) and does not fully document the current level of
strptimesupport.Final thoughts
A larger discussion should be had on modernizing
datetimeand fully supporting C99 (ideally newer)time.hformat tokens.Linked PRs