Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Help with date format

Expand Messages
  • Greg Webster
    Sorry, you re right...but this is easily accomplished with one line. $wholedate = 20000803 ; $wholedate =~ s/[ /- .//g; #removes / - and . Add as
    Message 1 of 21 , Sep 4, 2000
    • 0 Attachment
      Sorry, you're right...but this is easily accomplished with one line.

      $wholedate = '20000803';
      $wholedate =~ s/[\/-\\\.//g; #removes / - \ and . Add as needed
      @alldigits = split(//, $wholedate);
      $year = join('', @alldigits[0..3]);
      $month = join('', @alldigits[4..5]);
      $day = join('', @alldigits[6..7]);

      print "Year: $year : Month: $month : Day: $day\n";

      Greg

      On Mon, 04 Sep 2000, you wrote:
      >
      > hey, isn't the problem with this though, that you cannot as simply account
      > for the addition of spaces, dashes or slashes to the date? that was one of
      > the prerequisites of the person who had the question.
      >
      > for example, what if your date looked like this:
      > 2000-08-23
      >
      > or if it sometimes looked like the above and sometimes looked like this:
      > 20000823
      >
      > the program below would not work anymore.
      >
      > i'm a beginner, so let me know if i've missed something!
      >
      > maisha
      > -----Original Message-----
      > From: Greg Webster <greg@...>
      > To: perl-beginner@egroups.com <perl-beginner@egroups.com>
      > Date: Sunday, September 03, 2000 10:26 PM
      > Subject: Re: [PBML] Help with date format
      >
      >
      >
      >
      > Personally...
      >
      > To convert 20000803 (and be able to do cool things with the values
      > individually), I'd do something like the following:
      >
      > $wholedate = '20000803';
      > @alldigits = split(//, $wholedate);
      > $year = join('', @alldigits[0..3]);
      > $month = join('', @alldigits[4..5]);
      > $day = join('', @alldigits[6..7]);
      >
      > print "Year: $year : Month: $month : Day: $day\n";
      >
      > Then you can easily deal with all of the dates in bits. There's really no
      > reason to complicate matters here.
      >
      > BTW, I'm sure is Awk type formats and $1, $2, $3 etc...this could be
      > simplified
      > further.
      >
      > Greg
      >
      > --
      > < >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
      > | | | GREG WEBSTER - greg@... | | | |
      > <_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>
      --
      < >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
      | | | GREG WEBSTER - greg@... | | | |
      <_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>
    • Andrew Johnson
      ! Sorry, you re right...but this is easily accomplished with one line. ! ! $wholedate = 20000803 ; ! $wholedate =~ s/[ /- .//g; #removes / - and . Add
      Message 2 of 21 , Sep 4, 2000
      • 0 Attachment
        ! Sorry, you're right...but this is easily accomplished with one line.
        !
        ! $wholedate = '20000803';
        ! $wholedate =~ s/[\/-\\\.//g; #removes / - \ and . Add as needed

        Ouch! Greg, besides forgetting the closing ] on the character class,
        you do realize that your regex will remove a whole lot more than you
        think it does (removing all upper case letters and all digits, and
        several punctuation characters -- and it won't remove the '-'
        character).

        I think you meant: [\/\\\.-] , placement of the '-' is crucial inside
        of character classes.

        regards,
        andrew

        --
        Andrew L. Johnson http://members.home.net/andrew-johnson/
        I drink to make other people interesting.
        -- George Jean Nathan
      • Greg Webster
        Heh, I really should test what I write. Forgive me, it s been a hell of a week. You are absolutely right about the placement and order. Greg ... -- -
        Message 3 of 21 , Sep 4, 2000
        • 0 Attachment
          Heh, I really should test what I write. Forgive me, it's been a hell of a week.
          You are absolutely right about the placement and order.

          Greg

          On Mon, 04 Sep 2000, you wrote:
          > Ouch! Greg, besides forgetting the closing ] on the character class,
          > you do realize that your regex will remove a whole lot more than you
          > think it does (removing all upper case letters and all digits, and
          > several punctuation characters -- and it won't remove the '-'
          > character).
          >
          > I think you meant: [\/\\\.-] , placement of the '-' is crucial inside
          > of character classes.
          >
          > regards,
          > andrew
          >
          > --
          > Andrew L. Johnson http://members.home.net/andrew-johnson/
          > I drink to make other people interesting.
          > -- George Jean Nathan
          --
          < >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
          | | | GREG WEBSTER - greg@... | | | |
          <_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>
        • Maisha Walker
          ha ha ha - that s great! maisha ... From: Andrew Johnson ! just curious everyone, but why use d d instead of d{2} - even just ! for
          Message 4 of 21 , Sep 4, 2000
          • 0 Attachment
            ha ha ha - that's great!

            maisha
            -----Original Message-----
            From: Andrew Johnson <andrew-johnson@...>

            ! just curious everyone, but why use \d\d instead of \d{2} - even just
            ! for consistency sake? is there a particular reason for using \d\d
            ! instead?

            To be honest, here is why I did it that way:

            \d{4} is shorter than \d\d\d\d
            \d\d is shorter than \d{2}

            :-)

            andrew
          • Smith, Sheldon
            That s right. Allowing for optional delimiters was exactly what Andrew Johnson s regex did (with the pattern [ /-]? ). (See earlier post.) Simple substring
            Message 5 of 21 , Sep 6, 2000
            • 0 Attachment
              That's right. Allowing for optional delimiters was exactly what Andrew
              Johnson's regex did (with the pattern "[ /-]?"). (See earlier post.) Simple
              substring extractions just can't get the job done.

              Shel Smith

              > -----Original Message-----
              > From: Maisha Walker [mailto:maisha@...]
              > Sent: Monday, September 04, 2000 9:00 AM
              > To: perl-beginner@egroups.com
              > Subject: Re: [PBML] Help with date format
              >
              > hey, isn't the problem with this though, that you cannot as
              > simply account
              > for the addition of spaces, dashes or slashes to the date?
              > that was one of
              > the prerequisites of the person who had the question.
              >
              > for example, what if your date looked like this:
              > 2000-08-23
              >
              > or if it sometimes looked like the above and sometimes looked
              > like this:
              > 20000823
            Your message has been successfully submitted and would be delivered to recipients shortly.