Gossamer Forum
Home : Products : DBMan : Customization :

ARGH: date range search

Quote Reply
ARGH: date range search
I browsed the unofficial FAQ, but can't for the life of me figure out what's wrong with the following code for carrying out date searches. The database has a field called "date".

- to the search form in html.pl, I added select fields as follows:
$time1 = time();
$day1 = &get_date($time1 - (86400 *2));
$day2 = &get_date($time1 - (86400 *3));
$week1 = &get_date($time1 - (86400 * 8));
$week2 = &get_date($time1 - (86400 * 15));
$week3 = &get_date($time1 - (86400 * 22));
$month1 = &get_date($time1 - (86400 * 31));
$month2 = &get_date($time1 - (86400 * 61));
$month3 = &get_date($time1 - (86400 * 91));
$month6 = &get_date($time1 - (86400 * 181));
$year1 = &get_date($time1 - (86400 * 366));

print qq|<select name="date-gt">
<option value="$day1">Newer than 1 day</option>
<option value="$day2">Newer than 2 days</option>
<option value="$week1">Newer than 1 week</option>
<option value="$week2">Newer than 2 weeks</option>
<option value="$week3">Newer than 3 weeks</option>
<option value="$month1">Newer than 1 month</option>
<option value="$month2">Newer than 2 months</option>
<option value="$month3">Newer than 3 months</option>
<option value="$month6">Newer than 6 months</option>
<option value="$year1">Newer than 1 year</option>
<option value="---">All dates</option></select>|;


- sub get_date in db.cgi looks like this:
sub get_date {
my ($time1) = $_[0];
($time1) or ($time1 = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day-$months[$mon]-$year"; }


- I did apply the required mods to sub query:
if ($in{'$column-gt'} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($in{'$column-gt'}) or return "Invalid date format: '$in{'$column-gt'}'");
push(@search_gt_fields, $i); }
if ($in{'$column-lt'} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and (&date_to_unix($in{'$column-lt'}) or return "Invalid date format: '$in{'$column-lt'}'");}
$i++;


Now, when I carry out a search (for all entries), the query string does contain the appropriate date range settings (e.g. "date-gt=27-Jul-2000&ID=*"). But I still get all entries returned, and not just the ones with the appropriate date. (I also included a date_to_unix conversion loop for $in{'date-gt'} to db.cgi, just in case.)

Out of my wits - please help.

greetings,

kellner