Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Sorting by Date Help!

by poolpi (Hermit)
on Mar 17, 2009 at 22:11 UTC ( #751293=note: print w/ replies, xml ) Need Help??


in reply to Sorting by Date Help!

use strict; use warnings; use DateTime; my @sorted_dates = sort { DateTime->compare_ignore_floating($$b{'submitted'}, $$a{'submitted'}) } map { my ( $month, $day, $year ) = ( split( '/', $_ ) )[ 0 .. 2 ]; { qq(submitted), DateTime->new( year => $year + 2000, month => $month, day => $day, time_zone => 'Europe/Paris', ) } } qw{ 01/22/08 01/12/08 04/01/09 10/04/08 01/10/09 12/12/09 01/22/0 +9 01/12/09 12/30/08 12/22/08 12/15/08 01/05/09 01/19/09 01/21/09}; print $sorted_dates[$_]{'submitted'}->mdy('/'), "\n" for 0 .. $#sorted_dates; __END__ Output: 12/12/2009 04/01/2009 01/22/2009 01/21/2009 01/19/2009 01/12/2009 01/10/2009 01/05/2009 12/30/2008 12/22/2008 12/15/2008 10/04/2008 01/22/2008 01/12/2008


hth,
PooLpi

'Ebry haffa hoe hab im tik a bush'. Jamaican proverb


Comment on Re: Sorting by Date Help!
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (13)
As of 2014-09-30 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (378 votes), past polls