Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Date comparison

by cjf (Parson)
on Jul 05, 2002 at 17:17 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2025-07-18 01:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.