Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Date comparison

by ehdonhon (Curate)
on Jul 05, 2002 at 16:49 UTC ( [id://179679]=note: print w/replies, xml ) Need Help??


in reply to Date comparison

Take a look at Date::Parse. You can use that to convert them to unix timestamp, and then just do numeric comparison.

Replies are listed 'Best First'.
Re: Re: Date comparison
by George_Sherston (Vicar) on Jul 05, 2002 at 21:28 UTC
    ehdonon ++ this is by far the easiest solution, and worth spelling out so that it doesn't get lost in the subsequent controversy
    use Date::Parse; my @dates = qw[ 02/03/08 02/04/02 3:00pm 4:00am ]; my @sorted = sort {str2time($a) <=> str2time($b)} @dates; print $_,"\n" for @sorted; __END__ 02/04/02 4:00am 3:00pm 02/03/08
    - n.b. times are assumed to be *today* unless date is specified. This will handle a variety of different date / time formats.

    § George Sherston
      Since str2time() is a relatively expensive routine, this a perfect time for pulling out the "Orcish Maneuver".

      In the example above, change   my @sorted = sort {str2time($a) <=> str2time($b)} @dates; to

      my %cache; my @sorted = sort {($cache{$a} ||= str2time($a)) <=> ($cache{$b} ||= str2time($b)) } @dates;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found