Results 1 to 3 of 3

Thread: Perl Q - 1/1/2003 to 2003

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    Perl Q - 1/1/2003 to 2003

    I how i format a date like this

    01/01/2003
    to
    1/1/2003

    ??

    Thanks!

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Split it into components, ltrim all zeros and put it back together.

    Or a smart regexp:
    s/0*(\d+)\/0*(\d+)\/0*(\d+)/$1.'/'.$2.'/'.$3/e
    maybe with the slashes escaped in the second part.
    Last edited by CornedBee; Dec 15th, 2003 at 08:30 AM.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Addicted Member
    Join Date
    Sep 2002
    Location
    Durham, NC, US
    Posts
    218
    Or, instead of using backticks (which isn't bad):
    Code:
    s/^0|\/0//g
    Mind you, I haven't tested that, and its been a couple months since I've done RegEx in Perl. It should look for a zero at the beginning of the string, or a slash zero and delete them (replace them with nothing).
    Travis, Kung Foo Journeyman

    Web Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.5 Guide and Reference
    Perl: Documentation, Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    OSS: Mozilla, MySQL (Manual)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width