Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Answer: How do I convert date format between 'DD-MM-YYYY' and 'YYYY-MM-DD' back & forth?

( #614227=categorized answer: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $in_date = '30-04-2007';
    my $db_date = join '-', reverse split '-', $in_date;
    ...
    my $pr_date = join '-', reverse split '-', $db_date;
    print "in: $in_date; db: $db_date; pr: $pr_date\n";
    # in: 30-04-2007; db: 2007-04-30; pr: 30-04-2007
    
  2. or download this
    my $in_date = '02/05/2007'; # or 02.05.2007, or any non-digit-separato
    +rs
    my $db_date = join '-', reverse split /\D/, $in_date;
    ...
    my $pr_date = join $sep, reverse split '-', $db_date;
    print "in: $in_date; db: $db_date; pr: $pr_date\n";
    # in: 02/05/2007; db: 2007-05-02; pr: 02-05-2007
    

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2015-07-31 18:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (280 votes), past polls