0 votes
1 view
in Python by (12.7k points)

I'm utilizing dateutil.parser.parse to arrange a date from a string. Be that as it may, presently it stirs up the month and the day. 

I have a string that contains 05.01.2015. After

dateutil.parser.parse("05.01.2015")

it returns:

datetime.datetime(2015, 5, 1, 0, 0)

I thought it would return (2015,5,1,0,0)

How might I tell the code that the arrangement is dd.mm.yyyy

For the record, 25.01.2015 will be parsed as (2015, 1, 25, 0, 0), true to form.

1 Answer

0 votes
by (26.4k points)

You can just specify dayfirst=True:

>>> dateutil.parser.parse("05.01.2015", dayfirst=True)

datetime.datetime(2015, 1, 5, 0, 0)

This offers priority to the DD-MM-YYYY format rather than MM-DD-YYYY in situations where the date design is uncertain (for example at the point when the day is 12 or lower)

Want to learn python to get expertise in the concepts of python? Join python certification course and get certified

Related questions

0 votes
1 answer
asked Jul 26, 2019 in Python by selena (1.6k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...