Hi I am trying to parse date from a string using dateutil parser. But I am getting this error. Does the library accept python 'str' or 'unicode'? Does the string need any conversion? Tried with that, but no luck.
Asked
Active
Viewed 4,869 times
-1
-
What string are you trying? – Colin Oct 06 '17 at 03:34
-
1Please post your code in text form. – Adeel Ahmad Oct 06 '17 at 03:35
-
remove all the digit numbers before the date/time stamp in your message. – Tiny.D Oct 06 '17 at 03:46
1 Answers
0
i would put all the digit numbers before the date/time stamp in your message AFTER the date/time stamp, then that portion would be separated as a tuple.
fuzzy_with_tokens – If True, fuzzy is automatically set to True, and the parser will return a tuple where the first element is the parsed datetime.datetime datetimestamp and the second element is a tuple containing the portions of the string which were ignored:
Another alternative is simply seeking out the known date format using regex. Of course, this varies by use case
from dateutil.parser import parse
import re
date_pattern = re.compile('\d{2}\d{2}\d{2}')
def extract_date(filename):
matches = re.match(date_pattern, filename)
if matches:
return parse(matches.group(0))
else:
return None
extract_date('30\09\17.jpg')

Clay Chester
- 91
- 16