date sorting module

Discussion in 'Perl Misc' started by Sam, Sep 16, 2003.

  1. Sam

    Sam Guest

    Hello
    I just came from cpan, after doing some searches and before I get a module,
    wanted to ask if any one out there knows of a module that takes an array of
    dates and sort them regardless of the date formate.

    thanks
    Sam, Sep 16, 2003
    #1
    1. Advertising

  2. In article <3f66c9a3$>, Sam wrote:
    > Hello
    > I just came from cpan, after doing some searches and before I get a module,
    > wanted to ask if any one out there knows of a module that takes an array of
    > dates and sort them regardless of the date formate.


    If the dates doesn't follow any pattern, how could you sort it?
    Compare for example the US date format with som eof the European
    ones: Does one sort 9/7/2002 before or after 7/10/2002 if one
    doesn't know what format they are on?


    --
    Andreas Kähäri
    Andreas Kahari, Sep 16, 2003
    #2
    1. Advertising

  3. Sam <> wrote:

    > I just came from cpan, after doing some searches and before I get a module,
    > wanted to ask if any one out there knows of a module that takes an array of
    > dates and sort them regardless of the date formate.

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    You can't.


    How can you distinguish between these two formats for instance:

    09-07-2003 # MM-DD-YYY - September 7
    and
    09-07-2003 # DD-MM-YYY - July 9

    ??


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Sep 16, 2003
    #3
  4. Sam

    Mothra Guest

    Hi Sam,

    "Sam" <> wrote in message
    news:3f66c9a3$...
    > Hello
    > I just came from cpan, after doing some searches and before I get a

    module,
    > wanted to ask if any one out there knows of a module that takes an array

    of
    > dates and sort them regardless of the date formate.


    This might give you some ideas

    use strict;
    use warnings;
    use DateTime;
    my @new_dates;

    my @dates =("Sat, 19 Jul 2003 15:53:45 -0500","1996-02-03","08-Feb-1998
    14:15:29 GMT");


    foreach my $new_date (@dates) {
    push(@new_dates, DateTime::Format::Mytest->parse_datetime($new_date) );
    }

    print map {$_->datetime(), "\n"} sort @new_dates;



    package DateTime::Format::Mytest;

    use DateTime::Format::HTTP;
    use DateTime::Format::Mail;


    use DateTime::Format::Builder (
    parsers => { parse_datetime => [
    sub { eval { DateTime::Format::HTTP->parse_datetime( $_[1] ) } },
    sub { eval { DateTime::Format::Mail->parse_datetime( $_[1] ) } },
    ] }
    );
    Mothra, Sep 16, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    595
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,243
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    511
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    718
    Richard Heathfield
    Nov 8, 2003
  5. Matt
    Replies:
    11
    Views:
    404
    Aaron Bertrand [MVP]
    Nov 8, 2003
Loading...

Share This Page