Filter Gmail messages according to date

email
activities

#1

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.


#2

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))


#3

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.


#4

@ClaytonM +1