开发者

MySQL Inserting date value from a text file

I have the following date format

28 Aug 2010 17:40:58 +0000 

Can anyone suggest how I go about getting this into a date or datetime type when inserting into mysql

I'm importing from the file the following way.

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

I'm unsure as how to handle开发者_JS百科 the date value so it will be structured correctly for mysql.

Thanks


If you don't mind with lots of warnings and losing information on timezone (unable to convert timezone), 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

make that column to a varchar,
after load data into database,
perform the update update ... set column=str_to_date(column, '%d %b %Y %H:%i:%s')
and finally change the column data type to datetime


Take a look here. It seems that they got solution (briefly, the idea is to add variable to column list, and then set the column value based on 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');

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜