gtmeyer has asked for the wisdom of the Perl Monks concerning the following question:

Is there an easy way to drop the leading zeros from dates? For example, If someone enters a date as 07/04/2001, is there a way to simply convert that to 7/4/2001? I am really new at this, but my mind keeps going back to having to parse the string and see if the piece (Month or Day) is less than 10 then some how read the two digits individually and resmove the first. I'm sure there's a better way. Thanks!! Glenn.

Originally posted as a Categorized Question.

  • Comment on How do I drop leading zeros from a date like 07/04/2001 to read 7/4/2001??

Replies are listed 'Best First'.
Re: How do I drop leading zeros from a date like 07/04/2001 to read 7/4/2001??
by Kanji (Parson) on Nov 27, 2001 at 03:18 UTC

    If you can guarantee the year is never going to start with a 0 (ie, 2001 vs 01), then ...

    $date =~ s/\b0//g;

    Originally posted as a Categorized Answer.