I'm trying to parse a date and put it in the correct format, this is what I tried so far:
import csv
import sys
import os
import re
import fnmatch
import csv
from dateutil.parser import parse as parseDate
from datetime import datetime, time, timedelta
chaine = '16/12/201602:15:00'
date = chaine[:10] + " " + chaine[11:]
print date
newd = parseDate(date, yearfirst=True)
print newd
newd = newd.replace('-','')
newd = newd.replace(':','')
print newd
This is what I get as result:
16/12/2016 2:15:00
2016-12-16 02:15:00
Traceback (most recent call last):
File "t.py", line 25, in <module>
newd = newd.replace('-','')
TypeError: an integer is required
What do I miss here?
Thank you
newdis not a string. Try usingnewd = str(newd).replace('-','')instead ofnewd = newd.replace('-','').'16/12/201602:15:00', then your setting foryearfirstinparseDate(date, yearfirst=True)seems to be wrong too, but without effect on the result, so you can drop that option