Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
There's more than one way to do things
 
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 browsing the Monastery: (10)
As of 2014-04-16 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (416 votes), past polls