php - LOAD DATA LOCAL INFILE date format from csv
I have been trying to pull a file into a table and the only issue I'm having is importing the dates (currently in'MM/DD/YY'
format). No matter what I try they end up looking like'0008-12-14'
. That date is8/12/14
in the .csv file. I tried
SET ShipDate = STR_TO_DATE(@ShipDate,'%Y%m%d')
but then it imported them asNULL
. The table field is set asDATE
. Here's the code:
$query = <<<eof
LOAD DATA LOCAL INFILE 'file.csv'
INTO TABLE HS_import
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(AmountPaid,
ShipDate)
SET ShipDate = STR_TO_DATE(@ShipDate,'%Y%m%d')
eof;
Answer
Solution:
Yor format for the STR_TO_DATE is wrong. It should specify the INPUT format not the OUTPUT format:
So the whole thing should look like