Skip to content
Advertisement

Convert String (with other string in) in Date Object – Python

I’m trying to convert this French string : ’20 avril 2018 – Arrivée définitive’ as a Date Object.

JavaScript

I tried :

JavaScript

But I have this error :

JavaScript

Thank you in advance for your help.

I’m hoping that this will help someone.

Advertisement

Answer

As you can read in documentation The parse function returns datetime representing parsed date if successful, else returns None so while looping, the parse function returned None of which you tried to use date function causing an error.

I am not sure if it would help but If you check in console:

JavaScript

So string “21 septembre 2018” parses well but “21 septembre 2018 – Arrivée définitive” parses as None (nothing printed means None in this case)

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement