Filter Gmail messages according to date

Hi,
I am trying to read the emails(Gmail) of the previous week. For example, Today’s DateTime is Dec 22, Friday 7:30 pm. I want to read all the emails from Dec 15, Friday 7:30 pm to Dec 22, Friday 7:30 pm. I want to repeat this every week, so I don’t want to hardcode the DateTime. I am unable to get the logic.

Any help would be appreciated.

Assuming you have mails in a mail message list, try something like this directly in foreach (did not test, so play around with the logic)

messages.Where(Function(x) DateTime.Parse(x.Headers("Date"))> DateTime.ParseExact(now.ToString,"MMM d, yyyy 19:30:00",CultureInfo.InvariantCulture) AND DateTime.Parse(x.Headers("Date"))< DateTime.ParseExact(now.ToString,"MMM d, yyyy 19:30:00",CultureInfo.InvariantCulture))

1 Like

To compare dates like “x.Headers(“Date”)> now.AddDays(-7).ToString(“MMM d, yyyy 19:30:00”)”, you will need to compare DateTime types, so just need convert them.

Like so, CDate(x.Headers(“Date”).ToString) > CDate(now.AddDays(-7).ToString(“MMM d, yyyy 19:30:00”))

Or something like that.

@ClaytonM +1

Hi VVaidya,

Can you please help me around to filter datetime like reading mails from gmail, yesterday 6 AM to today 6AM.

list_ReadMail is the list of mails read in ‘Get IMAP Mail Messages’.

I have tried the solution, but error is poping up.

Thanks in advance