This is what i wrote to convert dates in PHP before putting them into db:

$new_date = dbDate($HTTP_POST_VARS["Date"]);

// Converts DD/MM/YY to YYYY/MM/DD
function dbDate($date) {
  $pos1=strpos($date,'/')+1;
  $pos2=strpos($date,'/',$pos1)+1;
  $month=substr($date,$pos1,$pos2-$pos1-1);
  if (strlen($month)==1) {
    $month="0".$month;
  }
  $day=substr($date,0,$pos1-1);
  if (strlen($day)==1) {
    $day="0".$day;
  }
  $year=substr($date,$pos2,strlen($date));
  if (strlen($year)<4) {
    if ($year < "90") {
      $year="20".$year;
    } else {
      $year="19".$year;
    }
  }
  $date=$year.'-'.$month.'-'.$day;
  return $date;
} // dbDate

Maybe able to run a similar function?

John (*\*)


-----Original Message-----
From: Bernhard Doebler [mailto:[EMAIL PROTECTED]]
Sent: 05 July 2001 12:46
To: [EMAIL PROTECTED]
Subject: Re: LOAD DATA INFILE


Hi,

thanks for your answer. You never have problems since youalways use the date
format in the standard way, no european exception ;-)

mmhhh... It's hard to make the company administering the original data base
change the export format. So I'll have to import dates as strings and
somehow convert dates (change the order of day, month and year as well as
the delimiter).

Any Tip's welcome.

Best Regards
Bernhard

----- Original Message -----
From: "--==[bMan]==--" <[EMAIL PROTECTED]>
To: "Bernhard Doebler" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, July 05, 2001 12:23 PM
Subject: Re: LOAD DATA INFILE


> From my experience, if you want to import data into a date field, you have
to make sure that the date format in your csv file conforms to a date format
required by MySQL.  This part is covered in MySQL documentation.   So, your
20.12.1999 date should become 2001-12-20 and so on.
>
> P.S.  Don't forget to specify "TERMINATED BY ','" while using LOAD DATA
INFILE.  I use this feature VERY often and never had any trouble.. :-)
>
> Bernhard Doebler wrote:
>
> > I have a CSV-file exported from another database.
> >
> > It contains fields with dates and dates and times. A somplefied CSV-file
version looks like so.
> >
> > 20.12.1999;21.12.1999 03:35:27
> >
> > When I import it with LOAD DATA INFILE... and use fieldtypes "date" and
"datetime" it sadly does not work. It imports as many records as lines are
given in the file to import but each date is zero (NULL). Is there a
possibility to import it that "simple" way rather to import it as text in
one table and export it using date conversion-functions in another table?
> >


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to