Filter Gmail messages according to date



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


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