Free tech support / small logo


How can I search Google Gmail messages within a date range?

I have a ton of email in my Gmail archive, and sometimes need to dig through older email. Problem is, if I do a search, it shows me all the most recent matches first when what I really want to do is, say, search for messages more than a year old, or 12-18 months ago or similar. Is there any way to do a more sophisticated search than just by keyword?


Dave's Answer:

I'm a big fan of Google's Gmail service, and have found that experimentation is a great thing in terms of its search, just as poking around and trying different things in Google's main search system can real all sorts of useful capabilities, including the ability to convert measurement and weight units and the ability to solve even fairly complicated formulas.

In Gmail, as with many Google properties, the real secret is to pay attention to the small print (does that sound like something your Dad might have told you when you were younger? :-)

For example, when you're in Gmail, here's what you see in the search area:

google gmail search area

Look closely. See the link "Show search options"? Click it:

google gmail search options

That's pretty interesting, isn't it? :-)

Now let's poke around a bit. If I do a search for "contract" on email that's between one and two years old (which is done, rather awkwardly, as being within six months of 18 months ago), the resultant URL is:

https://mail.google.com/mail/#advanced-search/subset=all&has=contract&within=6m&date=18+months+ago

So we can see that Gmail uses a different sort of URL notation for advanced searches with "#advanced-search/subset=all". The keyword is in the "has=" value, and then there's a "date=" and a "within=". The question is, can we use those as predicates directly in a search?

I'll try it, searching for "contract within:6m date:01/01/2008". The result? Zero.

Ah, well, okay, so that doesn't work. But what does?

Turns out that with a big of digging, Google has an advanced search help page that details the following long list of predicates:

operatordefinitionexample
from:message sender"from:dave" = all mail with 'dave' in sender field
to:message recipient"to:sydney" = all mail with 'sydney' in the destination field (including mail not from you)
subject:message subject"subject:dinner" = all mail that has 'dinner' in the subject
after:messages sent after a certain date"after:2009/03/01" = all mail sent after March 1, 2009 (date format must always be YYYY/MM/DD)
before:messages sent before a certain date"before:2009/01/01" = all mail sent before January 1, 2009.

There are many more entries (see the original Google article) but these are the key ones that most power users are going to focus upon. This also gives us the tools we need to do the search we really want to do:

"contract before:2008/06/01 after:2007/06/01"

That, finally, gives us all email that contains the word "contract" and was sent or received between June 1, 2007 and June 1, 2008.

All messages more than a year old? Just use "before:" and follow it with the previous year and current month and day. As I write this, it'd be "2008/06/21".

Sometimes experimentation fails, as we saw with my first stab, but exploring the help menus and everything else definitely reveals that the Gmail search system has quite a bit more power than is immediately obvious, and quite a bit more power than even you get with the 'advanced search' pane.









Subscribe!
Never miss another Q&A article! Click to subscribe: Add to Google Reader Add to My Yahoo! Subscribe in NewsGator RDF XML
Comments

The before: and after: search tags would appear to only apply to the date the mail was received in GMail... not when it was sent.... :(

Posted by: Grrr Power at October 4, 2010 2:24 PM

I have something to say, now that you mention it, but ...
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you for all your efforts on this Web site by buying you a cup of coffee!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Recent Entries


Search
I Need Help!
Need Help? Ask Dave Taylor!


© 2002 - 2012 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.