Convert email dates with full time zone to basic date and time

Hello, I am using a “get mail” activity and its returning the full date with time zone and I need to convert it to standard time. Basically, I want to pull emails if they are form today, and within the last 5 minutes. I tried using an if function but I cant figure out the syntax to get the today function to match with the same format

(this is what the mail.date.tostring returns) Sat, 08 Oct 2022 08:44:17 -0500

Hi @Nathan_Betters1,

What is the -0500? If you can tell me, I will try to find a solution.

Regards
Ömer

@Nathan_Betters1,

Without -0500, i made some operations.

Kindly check the screenshot.

Hi,

Can you try the following expression?

DateTime.ParseExact("Sat, 08 Oct 2022 08:44:17 -0500","ddd, dd MMM yyyy HH:mm:ss K",System.Globalization.CultureInfo.InvariantCulture)

DateTime.ParseExact(yourString,"ddd, dd MMM yyyy HH:mm:ss K",System.Globalization.CultureInfo.InvariantCulture)

Regards,

You can use one of the following as per your need:

mail.Headers(“Date”)
mail.Headers(“DateReceived”)
mail.Headers(“DateCreated”)

it will give you what you are looking for

These return the same values, which include time zones etc

tried both of these and get this error

Hi,

The above expression returns DateTime type. if you need string type, please add .ToString at the end of it.

Regards,

Not sure why it return the date with the zone for you. since you just need to compare the email time with the current time you can use a simple if condition:

mail.Headers(“Date”) >= Now.AddMinutes(5)

if mail.Headers(“Date”) returns a string you can use Convert.ToDateTime(mail.Headers(“Date”))