How to query Email by subject using o365 Get Email, which contains text and current date

Hi!
I’m trying to get my e-mails using o365 with subject E-mails like this:

Success Report 11-06-2023
Failed Report 30-04-2023

I was gonna try this code

"contains(subject,‘Success Report') and ReceivedDateTime eq "

I’ve tried putting the current date in a variable but I don’t know how to add it after eq

Hi @Shinjid

Try this
“contains(subject, ‘Success Report’) and startswith(ReceivedDateTime, ‘dd-MM-yyyy’)”

Hope it helps!!

Hi @Shinjid

Use the below filter.

“[Subject] LIKE ‘%Success%’ AND System.Text.RegularExpressions.Regex.IsMatch(item.Headers(“Date”).ToString, ‘\d{2}-\d{2}-\d{4}’)”

Hope it helps!!

1 Like

Thank you @Shinjid

If you find the solution Mark it as solution which help others.

Hope it helps!!

@Shinjid

It should be like this

"contains(subject,'Success Report') and ReceivedDateTime eq 2023-05-29"

Or

"contains(subject,'Success Report') and ReceivedDateTime gt 2023-05-28 and ReceivedDateTime lt 2023-05-30"

Cheers

This thread should give you everything you need.

1 Like

You can’t do this. It’ll never equal just a date. Internally, 2023-05-29 will be treated as 2023-05-29 00:00:00 so the email would have to be received at exactly midnight to match 2023-05-29. You have to do the gt/lt like you did in the second option.

2 Likes

Thanks! This helped a lot

Hi! Sorry for late reply. I got the idea for my answer from the link sent by postwick. I recommend you to check it first to fit with your requirement/s.

I did mine like

"contains(subject, 'Success Report') AND receivedDateTime ge " + datetime.Now.AddDays(-1).tostring("yyyy-MM-dd")

Since I’m only running this once daily. I just put the previous previous date(yesterday) as the reference for the greater than value of the receivedDateTime

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.