You the Man kellner!
works great!
Now onto my next problem....hehehe
here is the final out come.
sub get_date {
# --------------------------------------------------------
# Returns the date in the format "day of the week name-dd-mmm-yy".
# Warning: If you change the default format, you must also modify the &date_to_unix
# subroutine below which converts your date format into a unix time in seconds for sorting
# purposes.
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
my (@dwk) = qw!Mon Tue Wed Thur Fri Sat Sun!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$dwk[$dweek]-$day-$months[$mon]-$year";
}
sub date_to_unix {
# --------------------------------------------------------
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my ($date) = $_[0];
my (%months) = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
my (%dwk) = ("Mon" => 1, "Tue" => 2, "Wed" => 3, "Thur" => 4, "Fri" => 5,
"Sat" => 6, "Sun" => 7);
my ($time);
my ($dweek, $day, $mon, $year) = split(/-/, $date);
unless ($dweek and $day and $mon and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }
unless (defined($dwk{$dweek})) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0, $day, $months{$mon}, $year1);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}