I'm trying to parse a string to a date in this format : %Y%m%d%H%M%S
by this code :
from dateutil.parser import parse as parseDate
from datetime import datetime, time, timedelta
chaine = "01/10/201604:45:00"
print chaine
date = chaine[:10] + " " + chaine[11:]
print date
date = parseDate(date,yearfirst=True)
print date
i = str(date).replace('-','')
print i
i = str(i).replace(':','')
print i
i = str(i).replace(' ','')
print i
This is what I get as output:
01/10/201604:45:00
01/10/2016 4:45:00
2016-01-10 04:45:00
20160110 04:45:00
20160110 044500
20160110044500
Here, instead of getting 01 as the day and 10 as the month, i get 01 as month and 10 as day, meaning I get january instead of october.
In the other hand, when I change the chaine
to : 14/11/201615:30:00
I get the correct date: 20161114053000
: month then day.
Am I missing something here?
You can use
datetime.strptime()
to achieve that: