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

How do I sort something by date?

( #84383=categorized question: print w/ replies, xml ) Need Help??
Contributed by damian1301 on May 31, 2001 at 01:21 UTC
Q&A  > sorting


How would I sort something by date if the date's format were like so:




Answer: How do I sort something by date?
contributed by merlyn

## using a modified Schwartzian Transform, called the GSR sort... my @result = map { join "/", (/(....)(..)(..)/)[1,2,0]; } sort map { sprintf "%04d%02d%02d", (split /\//)[2,0,1]; } @input;
Answer: How do I sort something by date?
contributed by davorg

Also consider using a more sensible format for your dates. YYYY-MM-DD is much better because a) no-one will confuse months and days and b) you can sort it.

Answer: How do I sort something by date?
contributed by salva

If you are using DateTime objects, then you should considered using Sort::Key::DateTime for sorting.


  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (7)
    As of 2014-03-17 07:57 GMT
    Find Nodes?
      Voting Booth?

      Have you used a cryptocurrency?

      Results (341 votes), past polls