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 Answers2

1

Use dayfirst=True

Ex:

from dateutil.parser import parse 

print(parse('05/04/2019',dayfirst=True))
# --> 2019-04-05 00:00:00
Rakesh
  • 81,458
  • 17
  • 76
  • 113
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

m.rp
  • 718
  • 8
  • 22