#1
  1. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,617
    Rep Power
    595

    Date comparison and European vs. US formats


    I am trying to use DateTime::Format::Manip to create a date object for comparisons. My problem is European (apparently the default) vs. American formats. The method parse_datetime, returns undef with a format like 03/14/2013. How do I tell it to use US format (mm/dd/yyyy) rather than European format (dd/mm/yyyy)? TIA.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    You could use your own 'formatter' object:

    Code:
    use strict;
    use DateTime;
    use DateTime::Format::Strptime;
    
    my $us_parser = DateTime::Format::Strptime->new( pattern => '%m/%d%/Y',
                                                     on_error => 'croak',
                                                   );
    my $dt = $us_parser->parse_datetime('3/14/2013');
    print "$dt\n";

    Comments on this post

    • gw1500se agrees : Works perfectly. Thanks.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,617
    Rep Power
    595
    Oh. In other words I can't use DataManip.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo