Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

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

Q&A > dates and times > How do I convert date format between 'DD-MM-YYYY' and 'YYYY-MM-DD' back & forth? contributed by naikonta

Just in case you specify that the date must be in US-style (MM-DD-YYYY), then the above split won't work.
my $in_date = '11-24-2007'; # or 11/24/2007, or 11.24.2007, or any non +-digit-separators my @parts = split /\D/, $in_date; my $db_date = join '-', @parts[2, 0, 1]; # to get the original format: my $sep = '-'; my @parts = split $sep, $db_date; my $pr_date = join $sep, @parts[1, 2, 0]; print "in: $in_date; db: $db_date; pr: $pr_date\n"; # in: 11-24-2007; db: 2007-11-24; pr: 11-24-2007

Comment on Answer: How do I convert date format between 'DD-MM-YYYY' and 'YYYY-MM-DD' back & forth?
Download Code
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 cooling their heels in the Monastery: (6)
As of 2015-08-01 01:10 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 (285 votes), past polls