Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

How do I sort something by date?

by damian1301 (Curate)
on May 31, 2001 at 01:21 UTC ( #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 (register and) log in if you wish to add an answer

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (3)
    As of 2018-07-23 06:08 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (459 votes). Check out past polls.