Search code examples
pythonpython-dateutil

Why does a call to dateutil.parser.parse indicate november is december?


If I run the following:

from dateutil import parser
parser.parse("Wind10_463@Y2014_M11_D19", fuzzy=True)

I get this:

datetime.datetime(2014, 12, 19, 0, 0)

Why is it saying December not November?


Solution

  • It's not able to fully parse the structure of your string. When dateutil.parser.parse is missing one of the fields, such as the month, it will fill it in with the current month, which is December.

    From the docs:

    default: If given, this must be a datetime instance. Any fields missing in the parsed date will be copied from > this instance. The default value is the current date, at 00:00:00am.