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

Re: Sorting dates with the Schwartzian Transform

by FunkyMonk (Chancellor)
on Aug 03, 2011 at 16:20 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-28 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found