Alright, this one site I've started working on has been using dbman for years. It has a few date range searches, and now NONE of them work. All I did was add a new user. They are using the month/day/year date format, and it is being added to the database like that, no problems. Just the searching is problematic. Here is the relevant code:
In db.cgi:
# --------------------------------------------------------
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");
++$mon;
($mon < 10) and ($mon = "0$mon");
$year = $year + 1900;
return "$mon/$day/$year";
}
sub date_to_unix {
# --------------------------------------------------------
my ($date) = $_[0];
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($mon and $day and $year) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900; $mon = int($mon) - 1;
$time = timelocal(0,0,0,$mon, $day, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
They have JPDeni's excellent "What's New" MOD applied from: http://www.jpdeni.com/dbman/Mods/whatsnew.txt (as well as her bug fixes for the database). The "last 7 days" link looks like this:
In sub query of db.cgi the listnew code is:
if($in{'listnew'}) {
$days = 6; # Number of days for What's New, +1.
$new = &get_date(time() - ($days * 86400));
# Change Date below to match the *exact* name of your date field.
$in{'Date-gt'} = $new;
# Change 2 below to match the number of your date field.
$in{'sb'} = 19; # Number of your date field
$in{'so'} = 'descend';
}
19 is the number of my date field in default.cfg, which looks like:
This link returns hundreds of random records from the past year. Not just the ones within the last 7 days.
They also have the code to select records newer than a date selected from a drop-down menu. Here's the code for that in html.pl:
|;$time1 = time();
$day1 = &get_date($time1 - (86400 *2));
$day2 = &get_date($time1 - (86400 *3));
$day3 = &get_date($time1 - (86400 *4));
$day4 = &get_date($time1 - (86400 *5));
$day5 = &get_date($time1 - (86400 *6));
$day6 = &get_date($time1 - (86400 *7));
$day6 = &get_date($time1 - (86400 *8));
$week1 = &get_date($time1 - (86400 * 8));
$week2 = &get_date($time1 - (86400 * 15));
$week3 = &get_date($time1 - (86400 * 22));
$month1 = &get_date($time1 - (86400 * 31));
$year1 = &get_date($time1 - (86400 * 350));
print qq|<select name="Date-gt">
<option value="---" selected>Any Date
<option value="$day1"> today
<option value="$day2"> yesterday and today
<option value="$day3"> 3 days
<option value="$day4"> 4 days
<option value="$day5"> 5 days
<option value="$day6"> 6 days
<option value="$week1"> 1 week
<option value="$week2" selected> 2 weeks
<option value="$month1"> 1 month
<option value="$year1"> 1 year
</select>
Here's where the weirdness starts. If I select to search 3 days, it will show me hundreds of random records, none of which are from the last 3 days. If I select 2 weeks from the drop-down menu, the program will tell me that it's an invalid date format
I also have an advanced search form where you can write in dates. In html.pl this is like:
<br>Dates after <input type="text" size="10" name="Date-gt">
but before <input type="text" size="10" name="Date-lt"> (mm/dd/yyyy)
This also returns hundreds of random results that don't match the day.
What the heck?!? Please help me!
In db.cgi:
Code:
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");
++$mon;
($mon < 10) and ($mon = "0$mon");
$year = $year + 1900;
return "$mon/$day/$year";
}
sub date_to_unix {
# --------------------------------------------------------
my ($date) = $_[0];
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($mon and $day and $year) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900; $mon = int($mon) - 1;
$time = timelocal(0,0,0,$mon, $day, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
They have JPDeni's excellent "What's New" MOD applied from: http://www.jpdeni.com/dbman/Mods/whatsnew.txt (as well as her bug fixes for the database). The "last 7 days" link looks like this:
Code:
<a href="$db_script_link_url&listnew=1&view_records=1">Show last 7 Days</a>In sub query of db.cgi the listnew code is:
Code:
# last 7 days if($in{'listnew'}) {
$days = 6; # Number of days for What's New, +1.
$new = &get_date(time() - ($days * 86400));
# Change Date below to match the *exact* name of your date field.
$in{'Date-gt'} = $new;
# Change 2 below to match the number of your date field.
$in{'sb'} = 19; # Number of your date field
$in{'so'} = 'descend';
}
19 is the number of my date field in default.cfg, which looks like:
Code:
'Date' => [19, 'date', 20, 255, 0, &get_date(), '']This link returns hundreds of random records from the past year. Not just the ones within the last 7 days.
They also have the code to select records newer than a date selected from a drop-down menu. Here's the code for that in html.pl:
Code:
<br>Show records in the last: |;$time1 = time();
$day1 = &get_date($time1 - (86400 *2));
$day2 = &get_date($time1 - (86400 *3));
$day3 = &get_date($time1 - (86400 *4));
$day4 = &get_date($time1 - (86400 *5));
$day5 = &get_date($time1 - (86400 *6));
$day6 = &get_date($time1 - (86400 *7));
$day6 = &get_date($time1 - (86400 *8));
$week1 = &get_date($time1 - (86400 * 8));
$week2 = &get_date($time1 - (86400 * 15));
$week3 = &get_date($time1 - (86400 * 22));
$month1 = &get_date($time1 - (86400 * 31));
$year1 = &get_date($time1 - (86400 * 350));
print qq|<select name="Date-gt">
<option value="---" selected>Any Date
<option value="$day1"> today
<option value="$day2"> yesterday and today
<option value="$day3"> 3 days
<option value="$day4"> 4 days
<option value="$day5"> 5 days
<option value="$day6"> 6 days
<option value="$week1"> 1 week
<option value="$week2" selected> 2 weeks
<option value="$month1"> 1 month
<option value="$year1"> 1 year
</select>
Here's where the weirdness starts. If I select to search 3 days, it will show me hundreds of random records, none of which are from the last 3 days. If I select 2 weeks from the drop-down menu, the program will tell me that it's an invalid date format
I also have an advanced search form where you can write in dates. In html.pl this is like:
Code:
<b>Search by date range:</b> <br>Dates after <input type="text" size="10" name="Date-gt">
but before <input type="text" size="10" name="Date-lt"> (mm/dd/yyyy)
This also returns hundreds of random results that don't match the day.
What the heck?!? Please help me!