Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Sorting dates with the Schwartzian Transform

by FunkyMonk (Canon)
on Aug 03, 2011 at 16:20 UTC ( #918321=note: print w/ replies, xml ) Need Help??


in reply to Sorting dates with the Schwartzian Transform

Do I have to convert this column before the ST to a number,
A number or a string, it makes little difference
and after the ST convert it back to the DD-MM-YYYY format?
No, you just throw the sortable number/string away. Something like this:
print for map { $_->[0] } # extract original date sort { $a->[1] cmp $b->[1] } # Sort, using sortable date map { m/(\d\d)-(\d\d)-(\d{4})/; [$_, "$3$2$1"] # [original date, sortable date +] } <DATA>; __DATA__ 02-02-2007 01-01-2006 03-03-2009 02-02-2009

Output:

01-01-2006 02-02-2007 02-02-2009 03-03-2009


Unless I state otherwise, all my code runs with strict and warnings


Comment on Re: Sorting dates with the Schwartzian Transform
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-12-27 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls