0

I'm stuck with this thing (I'm a beginner in Python and it's become too complicated for me). I searched for days but never found any solution anywhere.

I have an History_string like this:

----------------------------------------------------------------
Jeu. 17/06/2021 - 16:12:48


Sent email 

----------------------------------------------------------------

Mer. 16/06/2021 - 11:34:43


meeting today

----------------------------------------------------------------
Lun. 14/06/2021 - 20:02:34


phone call today

----------------------------------------------------------------

and I would like to insert another string which contains another interaction with the customer, lets say New_interaction:

----------------------------------------------------------------
Mar. 15/06/2021 - 17:34:45


New interaction
----------------------------------------------------------------

So basically what I'm trying to do is searching the History_string until it founds a date less than New_interaction and insert New_interaction right there.

So the result would be :

----------------------------------------------------------------
Jeu. 17/06/2021 - 16:12:48


Sent email 

----------------------------------------------------------------

Mer. 16/06/2021 - 11:34:43


meeting today

----------------------------------------------------------------

Mar. 15/06/2021 - 17:34:45


New interaction

----------------------------------------------------------------

Lun. 14/06/2021 - 20:02:34


phone call today

----------------------------------------------------------------

How can I achieve that?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Nico44044
  • 125
  • 8
  • Hour is always the same? Could you also shared what you have already tried? – mastersom Jun 18 '21 at 08:01
  • Hi, thank you for your interest, no the hour isn't always the same but the date format is. I already tried to deal with things like History_string.find( – Nico44044 Jun 18 '21 at 09:22
  • Well, you would have to convert your date time string into a date time object in order to compare. U can use the datetime library in python for that. Since your time could be different the comparison also has to take this into account. Give it a go, if you dont manage, post your code and i will try to fix it for you. – mastersom Jun 18 '21 at 09:29
  • OK but how can I isolate the date as my string contain text + dates ? – Nico44044 Jun 18 '21 at 10:08
  • check this https://stackoverflow.com/questions/3276180/extracting-date-from-a-string-in-python – mastersom Jun 18 '21 at 10:22

0 Answers0