3
votes

I use dateutil.parser.parse function to convert something like 01.01 or 12.31 to datetime where year is a current year. So 01.01 becomes 01.01.2019. This code however does not work:

from dateutil import parser.parse
date = '05.05'
print(parser.parse(date))

Result:

>>>  datetime.datetime(2019, 3, 5, 0, 0)

What am I doing wrong?

1

1 Answers

1
votes

You should put - or nothing between them:

In [3]: from dateutil.parser import parse
   ...: date = '05-05' # also works with '05 05'
   ...: print(parse(date))
2019-05-05 00:00:00