Search Events: String was not recognized as a valid DateTime when trying to get the exact date

I am getting this error Search Events: String was not recognized as a valid DateTime.

This happenes because I am trying to make a bot that look for events in my google calendar.

Example: If i have a meeting at 2pm I want a box message to pop up saying i have a meeting.

the error is happening because
I added a search event that looks for my emails subject
“DateTime.ParseExact(split(mail.Subject, “@”)(1), " ddd MM d,yyyy h:m tt”, System.Globalization.DateTimeFormatInfo.InvariantInfo)"

The subject of the email is
Invitation: the beginning @ Wed Dec 22, 2021 8am - 12:30pm (EET)

What shall I do to fix this.

@Zeid_Abawi_MiddleEast Hi, Try with “/” for dates & hh:mm:ss" for time.

@Zeid_Abawi_MiddleEast , for furthur code refer this link…

Can you write it down to me

Can you write down to me
the date format to get rid of this error?
@Majunu09

Now.ToString(“ddMMyyyy_HHmmss”)
to get current date, month and year with time.
Now.ToString(“ddMMyyyy”)
to get current date. like wise …

Not working I having same error

I want to make sure that the search event is ready the email subject to extract the date and time correctly.

OR

Is there a way that the bot can read the events in my calendar and gives me the exact time for each event?

@Zeid_Abawi_MiddleEast , You want to extract the date and time which is mentioned on the mail subject?

@Majunu09 Yes!!

so i need to add the start date and end date for the search event.

Break the thought process down into smaller steps.

If "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.

Try this:
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

if: myDate.contains(":") 
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)

@Jeroen_van_Loon thank you!! but the .last is not recognised.

So this did not work.

replace .last by (1), and the .first by (0) then…
It works in my testcode

Try this example.
Main.xaml (6.8 KB)

Thank you so much!! I am very new to UIPath

And I am trying to do this so if you can help me please do.

I want to to read my google calendar

when ever I have an event (Let’s say I have an meeting at 3Pm-4pm) I want the bot to change my google status from available to busy and keep running all day.

can you help me with this? @Jeroen_van_Loon

Well… yes and no :slight_smile:

I’m willing to help you on specific questions, though I will not build your entire script, and deprive you of a valuable learning experience. :wink:

In essence it starts with proper process design. Lets assume for now that your process is as it should be, and there are no alternative sollutions other than RPA.

The essence of RPA is that it mimics the actions as if you would do it manually. So, if you would want to do the action as you describe, what are the detailed steps. Then you “simply” build each individual step.

By breaking a process down into the smallest possible steps, the sollution often becomes much more apparant compared to describing an entire processflow in one single sentence.

I hope this helps a bit in your journey. Undoubtly you’ll encounter challenges with the small steps too… but that what this forum is for!

@Jeroen_van_Loon

Okay I will break it down here and I will tell you what i did and what is stopping me.

I started by adding a search event to my own calendar – then using this output (varname) then it goes to gmail status and changes it to busy instead of available.

my problem is that the bot is check my calendar in general not I want it to check it day by day hour by hour.

So if the I have a meeting at 4pm to change the status to busy.

You would then either need a bot that is running 24/7 only to do that specific task (which is a huge waste of a bot imho), or design the process as follows:

  1. a bot that reads the calendar for existing appointments that day. You run this bot at least once a day, maybe more if your daily schedule changes a lot mid day. Lets call this the ReadCalendar bot.
  2. a bot that, when triggered, changes your status to either busy or available, whichever is applicable. This bot does not start on its own. This is the ChangeStatus bot.

As said the 1st bot reads the calendar. When it reads your calendar it checks for appointments that day, and for each appointment it creates a queueitem as a task for the changestatus bot. You can time schedule this 1-2 minutes before the actual appointment, and once again for the end of the appointment. By using queue-triggers in the Orchestrator the change status bot will run just before your meeting, change your status, and change it back at the end with a second run, by the second queueitem.

All in all this could work, assuming all the ui-steps involved can be solved.

Personally I’d never build this, since the time it would take to build, test and maintain the bot will not earn itself back cause it takes 10 seconds to change your status prior to a meeting I guess…

It kinda has a negative businesscase in my opinion.

@Zeid_Abawi_MiddleEast ,
Main.xaml (10.4 KB)
Hi I tried in this method, where meeting linq or message/ Mail will be sent to your gmail or outlook mail. This method reads all mail and filter out the subject of the mail as you said Invitation: the beginning @ wed Dec 22, 2021 8am, If this matches then you can set avaiable to busy. Try it out. I have attached the xaml.

@Jeroen_van_Loon

thank you!! I totally agree with you!1 but this is a project at my job i need to finish it.

I just need the new datetime.pase to make it work

I will share my the main I did to show you what i did.
Main.xaml (46.3 KB)