1

I am trying to convert a string (utf-8) using French date format to datetime using strptime:

import datetime as dt
from __future__ import unicode_literals
a = "Février 2017".encode('utf-8')
dt.datetime.strptime(a,"%B %Y")

Result:

ValueError: time data 'F\xc3\xa9vrier 2017' does not match format '%B %Y'

Problem is, strptime doesn't seem to handle unicode very well:

import datetime as dt
from __future__ import unicode_literals
a = "Février 2017"
dt.datetime.strptime(a,"%B %Y")

Result:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 1: ordinal not in range(128)

Is there either an accepted format or an alternative to strptime?

  • 1
    Thanks a lot! Solution here : https://stackoverflow.com/questions/26294333/parse-french-date-in-python import dateparser a = "Février 2017" print(dateparser.parse(a).date()) – Thibault Lorrain Mar 19 '18 at 18:33

0 Answers0