Using DBMan for a water quality education site. To make it brief, their water data requires date entry in MM/DD/YY format. Works fine.
The problem: When using a 2nd db for their scheduling info, I'm trying to make it so users can select a month and get all entries WITHOUT making "05" return "06/05/99" date.
Any ideas? I am including my get_date routines:
sub get_date {
# --------------------------------------------------------
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
my (@months) = qw!01 02 03 04 05 06 07 08 09 10 11 12!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$months[$mon]\/$day\/$year";
}
sub date_to_unix {
# --------------------------------------------------------
my ($date) = $_[0];
my (%months) = ("01" => 0, "02" => 1, "03" => 2, "04" => 3, "05" => 4, "06" => 5,
"07" => 6, "08" => 7, "09" => 8, "10" => 9, "11" => 10,"12" => 11);
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($mon and $day and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
------------------
farlane aka andrew mcfarlane
www.leelanau.com/pages/
The problem: When using a 2nd db for their scheduling info, I'm trying to make it so users can select a month and get all entries WITHOUT making "05" return "06/05/99" date.
Any ideas? I am including my get_date routines:
sub get_date {
# --------------------------------------------------------
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
my (@months) = qw!01 02 03 04 05 06 07 08 09 10 11 12!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$months[$mon]\/$day\/$year";
}
sub date_to_unix {
# --------------------------------------------------------
my ($date) = $_[0];
my (%months) = ("01" => 0, "02" => 1, "03" => 2, "04" => 3, "05" => 4, "06" => 5,
"07" => 6, "08" => 7, "09" => 8, "10" => 9, "11" => 10,"12" => 11);
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($mon and $day and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
------------------
farlane aka andrew mcfarlane
www.leelanau.com/pages/