Filter email date received

Hello,

I need to filter emails by the received date using a value from Excel config.
The date value from config is in the format string = “01052026 12:00:00” (ddMMyyyy HH:mm:ss).
Currently, I am using the “For Each Email” activity and want to apply this filter in the Additional Filters section.

Thank you.

if you are filtering outlook mail messages mail header property will have the received date:

Dim ReceivedDate As DateTime = OMailMessage.Headers(“Date”)

as for your date string - you need to parse it to proper date var

Dim DateInput As String = “01052026 12:00:00” 'ddMMyyyy HH:mm:ss format
Dim format As String = “ddMMyyyy HH:mm:ss” 'which format should it read as.
Try
Dim ResultDate As DateTime = DateTime.ParseExact(DateInput, format, CultureInfo.InvariantCulture, DateTimeStyles.None)
Catch ex As Exception
Console.WriteLine("error: " & ex.Message)
End Try

@golla.sandeep

I want filter in box red.

Can you suggest me?

try passing this

ResultDate.Date.ToString(“MM/dd/yyyy HH:mm tt”)

into the Date Filter value…

also, i think it better to use “>” or “<” rather than “=” for date filter

@Stef_99

Follow the below steps,

First get date from your config file and convert that in datetime format from string.
Then use that filtered datetime in for each email in addition filter.

Expression to convert the config date in datetime format

DateTime.ParseExact(strDate.Trim,“ddMMyyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)

From above screenshots
First assign activity, strDate is getting from config file.
If you dont want to use this assign activity, in second assign you can directly wirte expression as like below,

DateTime.ParseExact(Config(“mailDate”).ToString.Trim,“ddMMyyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)

If you use this expression then no need of first assign activity, and then in for each email in additional filter section do same as below screenshot

Please mark it as solution if this works.

Happy Automation

@yedukondaluaregala No option for use variable as below.

@Stef_99 Hope you are using 365 activities. Please confirm which activity you are using.

Above are 365 activities i used.

@yedukondaluaregala I use activity use Desktop Outlook app and inside use For each email (UiPath.Mail.Activities.Business.ForEachEmailX)

@Stef_99

Instead of these classic activites can you try using Microsoft 365 activities,

@Stef_99

If you dont want use 365 activities,
Use the activity
Get Outlook Desktop Mail Messages this will ge the email and here in property section there additional filter property under that you can use below expression,

“[ReceivedTime] >= '” + currentdate.ToString(“MM/dd/yyyy hh:mm tt”) + “'”

And create a output variable for this activity(lstMailmessages),
then use For each activity, pass above created variable lstMailmessages in for each activity.

Happy Automation

@yedukondaluaregala

Now I use desktop outlook app activity. I don’t want change code existing.
I have condtion for fileter subject and sender as below.

How can I add a date filter as well?

Thank you.

Where you mention this expression,
can you show the steps that you followed. so that i can give you right solution.

Now I filter Subject , from email as below.

I would like to filter emails by date as well. How can I add this condition to the filter?

@Stef_99

Then you can add the one more condition and in same expression like below

CurrentMail.DateAsDateTime>= currentdate

full condition that you need to write in if actiivty

fromEmail_List.Any(Function(x) CurrentMail.From.Address.ToLower.Contains(x.ToLower)) AndAlso
SubjectEmail_List.Any(Function(x) CurrentMail.Subject.ToLower.Contains(x.ToLower)) AndAlso
CurrentMail.DateAsDateTime>= currentdate

It will give result if all conditions are true.

Hope it works!