Swap 2007-03-15 to 15-03-2007

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Krustov

    Swap 2007-03-15 to 15-03-2007

    Swap 2007-03-15 to 15-03-2007

    Given i have 50,000 dates in a text file to change i'm looking for the
    fastest way of doing it .

  • Floortje

    #2
    Re: Swap 2007-03-15 to 15-03-2007

    Krustov schreef:
    Swap 2007-03-15 to 15-03-2007
    >
    Given i have 50,000 dates in a text file to change i'm looking for the
    fastest way of doing it .
    lotsa ways .. try this one

    $pieces=explode ($date,'-');
    $newdate = $pieces[2].'-'.$pieces[1].'-'.$pieces[0];

    or take a look at the mysql date format or use substr() or whatever else
    you can think of :-)

    --
    Arjen
    HondenPage: alles over uw hond of honden,fokkers en puppy's. Je vindt hier het hondenforum, honden foto's, fokkers, puppy's, de honden encyclopedie en nog veel meer !

    Comment

    • Rik

      #3
      Re: Swap 2007-03-15 to 15-03-2007

      On Fri, 16 Mar 2007 19:15:31 +0100, Krustov <me@privacy.net wrote:
      Swap 2007-03-15 to 15-03-2007
      >
      Given i have 50,000 dates in a text file to change i'm looking for the
      fastest way of doing it .
      Fastest way, if the format is consistent:

      $date_array = explode('-',$string);
      array_reverse($ date_array);
      $string = implode('-',$date_array);

      But as it is a textfile:

      $oldfile = '/path/to/old/file';
      $newfile = '/path/to/new/file';
      $old = fopen($oldfile, 'r');
      $new = fopen($newfile, 'w');
      while($data = fscanf($old,"%s-%s-%s\n")){//change according to format
      array_reverse($ data);
      fwrite($new,imp lode('-',$data)."\n");
      }
      --
      Rik Wasmus

      Comment

      • Krustov

        #4
        Re: Swap 2007-03-15 to 15-03-2007

        <comp.lang.ph p>
        <Floortje>
        <Fri, 16 Mar 2007 19:24:02 +0100>
        <45fae0c2$0$974 37$dbd45001@new s.wanadoo.nl>
        $pieces=explode ($date,'-');
        $newdate = $pieces[2].'-'.$pieces[1].'-'.$pieces[0];
        >
        That looks fine and just what i'm after - thanks dude .

        Comment

        • Krustov

          #5
          Re: Swap 2007-03-15 to 15-03-2007

          <comp.lang.ph p>
          <Rik>
          <Fri, 16 Mar 2007 19:31:00 +0100>
          <op.tpaodyb7qnv 3q9@metallium>
          Fastest way, if the format is consistent:
          >
          $date_array = explode('-',$string);
          array_reverse($ date_array);
          $string = implode('-',$date_array);
          >
          Saved to disk although Floortge's method might be more practical as i
          might want to add a extra line of text and only use a part of the date .

          Comment

          Working...