1

while parsing the date using 'dateutil parser' and even by 'moment parser' in python for the date dd/mm/yyyy eg 04/05/2019 it reflects this 05/04/2019 i.e it takes month as the date and vice versa. while if i try the same thing for a date greater than 12 will give the correct output, any solutions ?

import moment
print(moment.date('05/04/2019')) //date:05 month:04 year:2019

output: 2019-05-04T00:00:00+05.50 //considers date as month and vice versa which is wrong.

but if i try this

import moment
print(moment.date('13/04/2019')) //date:12 month:04 year:2019

output: 2019-04-13T00:00:00+05.50

2 Answers 2

1

Use dayfirst=True

Ex:

from dateutil.parser import parse 

print(parse('05/04/2019',dayfirst=True))
# --> 2019-04-05 00:00:00
Sign up to request clarification or add additional context in comments.

Comments

1

You have to specify the format for the date:

moment.date("13/04/2019", "%d-%m-%Y")

otherwise the library will use a default format, obviously since there are only 12 months any number greater than that will be treated as day or year.

Please check the documentation https://github.com/zachwill/moment

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.