-2
print(dateutil.__version__)

# shows 2.8.1

from dateutil.parser import parse

print(parse('September 29,2019'))
# datetime.datetime(2021, 9, 29, 0, 0),  SHOULD BE '2019' for the year.

PYTHON 3.8, WIN10 try different laptops, the same results. please see attached screen copy for more detail.

https://i.stack.imgur.com/U6cVj.png

Prune
  • 76,765
  • 14
  • 60
  • 81
xzrc571
  • 1
  • 1
  • 1
    Please go through the [intro tour](https://stackoverflow.com/tour), the [help center](https://stackoverflow.com/help) and [how to ask a good question](https://stackoverflow.com/help/how-to-ask) to see how this site works and to help you improve your current and future questions, which can help you get better answers. We expect you to get reasonably familiar with the usage before posting -- keep in mind the site's stated purpose. – Prune Mar 21 '21 at 16:03
  • Please provide the expected [MRE - Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Show where the intermediate results deviate from the ones you expect. We should be able to paste a single block of your code into file, run it, and reproduce your problem. This also lets us test any suggestions in your context. Off-site links and images of text are not acceptable; your posting must be self-contained, in keeping with the purpose of this site. – Prune Mar 21 '21 at 16:03
  • Make sure to use a space after the comma. – Axisnix Mar 21 '21 at 16:05

1 Answers1

1

The basic problem is that the date you give as an argument is not quite in one of the expected formats. You need to clean the input before you feed it to the parser.

Here's a quick example of the problem:

from dateutil.parser import parse

print(parse('September 29,2019'))
print(parse('September 29, 2019'))

Output:

2021-09-29 00:00:00
2019-09-29 00:00:00

Refer to the package documentation for the input requirements. If your program input doesn't conform to those requirements, you need to pre-process your data. IN this case, simply inserting a required space fixes the problem.

Prune
  • 76,765
  • 14
  • 60
  • 81