Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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.

Comment on Re: Date comparison
Download Code

Log In?

What's my password?
Create A New User
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 browsing the Monastery: (4)
As of 2015-11-28 08:41 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (740 votes), past polls