http://qs321.pair.com?node_id=179687


in reply to Date comparison

Date::Calc should do the job. For your first situation with dates in year/month/day format:

my $string_one = "02/03/08"; # assuming year/month/day my $string_two = "02/04/02"; my @date_one = split /\//, $string_one; my @date_two = split /\//, $string_two; $date_one[0] = 20 . $date_one[0]; $date_two[0] = 20 . $date_two[0]; my $time_one = Date_to_Time(@date_one, 0, 0, 0); # 0s are for hour/min +/sec my $time_two = Date_to_Time(@date_two, 0, 0, 0); if ($time_one > $time_two) { print "$time_one is newest.\n"; } elsif ($time_one < $time_two) { print "$time_two is newest.\n"; } else { print "Same date (to the nearest day).\n"; }

Comparing dates in hour:minuteAM/PM should be simple as well, just split the string for the hour, minute, and AM/PM parts, add 12 to the hours if it contains PM, convert to minutes, and compare.