Build a Custom Date Range Search Form

Search only Google pages indexed today, yesterday, the last 7 days, or last 30 days.

Google has a date-based search [Hack #16] but uses Julian dates. Most people can’t convert Gregorian to Julian in their heads. But with a conversion formula and a little Perl scripting, you can have a Google search form that offers to let users search Google pages indexed today, yesterday, the last 7 days, or the last 30 days.

The Form

The frontend to the script is a simple HTML form:

<form action="http://path/to/cgi-bin/goofresh.cgi" 
Search for:<br />
<input type="text" name="query" size="30" />
<p />
Search for pages indexed how many days back?<br />
<select name="days_back">
<option value="0">Today</option>
<option value="1">Yesterday</option>
<option value="7">Last 7 Days</option>
<option value="30">Last 30 Days</option>
<p />
<input type="submit" value="Search">

The form prompts for two user inputs. The first is a Google query, complete with support for special syntax ["Special Syntax” in Chapter 1] and syntax mixing ["Mixing Syntaxes” in Chapter 1]; after all, we’ll just be passing your query along to Google itself. The second input, a pull-down list, prompts for how many days’ worth of search the form should perform.

The Code

Note that this script just does a couple of date translations in Perl and redirects the browser to Google, altered query in tow. It’s just a regular query as far as Google is concerned, so it doesn’t ...

Get Google Hacks, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.