A strptime()
you have to pass the string that specifies the format in which your text is supposed to be. You have set "%d-%B-%Y"
, but that is not the text format, but it would be "%d de %B de %Y"
.
However, since the name of the month appears in Spanish in your text, you will have to make sure you have set the locale
of that language. Otherwise, possibly strptime()
will wait november
as the month name and it will also fail.
The following works for me:
import datetime
import locale
locale.setlocale(locale.LC_TIME, "es_ES")
fecha = "6 de noviembre de 2018"
t = datetime.datetime.strptime(fecha, "%d de %B de %Y")
print(t)
2018-11-06 00:00:00