MySQL Insert date value from text file

I have the following date format

28 Aug 2010 17:40:58 +0000 

Can anyone suggest how can I get this in the type of date or date when you paste in mysql

I am importing the following path from the file.

 load data local infile 'uniq.csv' into table tblUniq fields terminated by ',' enclosed by '"' lines terminated by '\n' (uniqName, uniqCity, uniqComments) 

I'm not sure how to handle the date value, so it will be structured correctly for mysql.

thanks

+4
source share
2 answers

If you do not mind a lot of warnings and lose time zone information (you cannot convert the time zone), you can convert the above answer to:

 load data local infile 'uniq.csv' into table tblUniq ... (uniqName, uniqCity, uniqComments, @date_val) SET datetime_column=str_to_date(@date_val, '%d %b %Y %H:%i:%s'); 

OR

enter this column in varchar ,
after loading the data into the database,
update update ... set column=str_to_date(column, '%d %b %Y %H:%i:%s')
and finally change the column data type to datetime

+2
source

Take a look here . It seems that they got the solution (in short, the idea is to add a variable to the column list, and then set the column value based on the formatted value of this variable:
load data local infile 'uniq.csv' into table tblUniq .....
(uniqName, uniqCity, uniqComments, @date_val)
SET datecolumn = date_format(str_to_date(@date_val, '%d-%M-%Y'), '%m/%d/%Y');

+2
source

All Articles