Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by naikonta (Curate)
on May 08, 2007 at 19:36 UTC ( [id://614228]=note: print w/replies, xml ) Need Help??


in reply to How do I convert date format between 'DD-MM-YYYY' and 'YYYY-MM-DD' back & forth?

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 Re: 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://614228]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-18 22:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found