I've got a number of datetimes in a spreadsheet that look like this:
July 29, 2022 @ 9:44 AM
Aug 2, 2022 @ 6:30 PM
...
I'm attempting to parse these with the following but I get an exception:
>>> import arrow
>>> myformat = "MMM D, YYYY @ H:MM A"
>>> arrow.get("Aug 2, 2022 @ 11:37 PM", myformat)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\enricojr\Projects\python-lox\.venv\lib\site-packages\arrow\api.py", line 91, in get
return _factory.get(*args, **kwargs)
File "C:\Users\enricojr\Projects\python-lox\.venv\lib\site-packages\arrow\factory.py", line 295, in get
dt = parser.DateTimeParser(locale).parse(
File "C:\Users\enricojr\Projects\python-lox\.venv\lib\site-packages\arrow\parser.py", line 346, in parse
return self._build_datetime(parts)
File "C:\Users\enricojr\Projects\python-lox\.venv\lib\site-packages\arrow\parser.py", line 701, in _build_datetime
datetime(
ValueError: month must be in 1..12
>>> arrow.__version__
'1.2.2'
>>>
Documentation states that "MMM" is the token for abbreviated months, but it's expecting a number from 1 - 12 instead. Am I using the tokens incorrectly, or is something else wrong here?
Python version: 3.10.4 Arrow version: 1.2.2 Operating System: Windows 10, and locale is reported by Python as en_US
.
>>> import ctypes
>>> windll = ctypes.windll.kernel32
>>> windll.GetUserDefaultUILanguage()
1033
(1033 is en_US)
from How to correctly use the "MMM" parse token in Arrow Python
No comments:
Post a Comment