Break the thought process down into smaller steps.
"the beginning @ Wed Dec 22, 2021 8am - 12:30pm (EET)" is your source string, and you try and take the date component by splitting it based on the
@ character you are left with this:
" Wed Dec 22, 2021 8am - 12:30pm (EET)"
If you parse this as a date it is indeed an incorrect format… you need to eliminate the endtime as well before it is even remotely parsable into a date.
split(split(mail.Subject, “@”).last, "-").first.trim
This should yield
"Wed Dec 22, 2021 8am"
This should match your initial datetime.parrceexact format with a few corrections for the spaces:
"ddd MMM d, yyyy htt"
The next problem is the time notation. 8am has no minute component, whereas 8:01 does. You need to account for that as well if you want it to be universal for eacht time of day. Because without minutes the time format is “htt” and with minutes it is “h:mmtt” and a mismatch leads to the parse error again.
You could use regex to rewrite 8am to 8:00am, and the same for pm, or do a relative simple if then:
Assign: myDate = split(split(mail.Subject, “@”).last, "-").first.trim
then: assign format = "ddd MMM d, yyyy h:mmtt"
else: assign: format = "ddd MMM d, yyyy htt"
Assign: appointmentStart = DateTime.ParseExact(myDate, format, System.Globalization.DateTimeFormatInfo.InvariantInfo)