Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1479
  • Last Modified:

Perl, convert date string from format mm/dd/yyyy (12/15/2010) to yyyy-mm-dd (2010-12-15)

Perl,

How do I convert date string from format mm/dd/yyyy (12/15/2010) to yyyy-mm-dd (2010-12-15) using any of the Perl "date" library.  Because using the Perl "date", the date can be checked for validity.

0
rgbcof
Asked:
rgbcof
  • 2
3 Solutions
 
ozoCommented:
s#(\d+)/(\d+)/(\d+)#$3-$1-$2#
or
join'-',(split/\D/)[2,0,1];
0
 
rockiroadsCommented:
could u make use of strtotime?
something along these lines


      $newDate = date("Y-m-d", strtotime($dt));


where $dt is your original date
0
 
rockiroadsCommented:
u could possibly use mktime as well to create a date, not as good though
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now