Convert date to Perl / regex format

I am trying to convert a string to a dateformat such as "Aug 12/11" .. to "YYYY-MM-DD", which in this example will be "2011-08-12".

What would be the best perl / regex for this conversion? I was able to do this by parsing each and translating it manually .. but I assume there is a quick way to do this with perl / regex. Thank.

+5
source share
2 answers

I would recommend not parsing such dates, especially when trying to find one or two regular expressions. There are many existing perl modules for this, such as Date::Manip. In this article, your many options are reasonably covered .

+4
source

Time :: Piece has been a core module for a long time, it has the ability to parse a string in a Time :: Piece object, which it can then format for you in 10 gazillion different formats. If Time :: Piece is not installed, you can try to find some of the other hundreds of time modules you can see, listed in cpan. (use one liner: perl -e "use Module :: IHope :: IsHere || die \ 'Not found \'").

`Time::Piece->strptime(STRING, FORMAT)
                        # see strptime man page. Creates a new
                        # Time::Piece object`

.

+2

All Articles