Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Date comparison

by cjf (Parson)
on Jul 05, 2002 at 17:17 UTC ( #179687=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://179687]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2021-10-19 13:11 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (76 votes). Check out past polls.