I want to upload my csv file that contains yyyy-mm-ddThh:mm:ss.sssZ
data.
When I set DATETIME
type in MySQL,
I got error code 1292.
MySQL How can I upload yyyy-mm-ddThh:mm:ss.sssZ
type successfully?
I want to upload my csv file that contains yyyy-mm-ddThh:mm:ss.sssZ
data.
When I set DATETIME
type in MySQL,
I got error code 1292.
MySQL How can I upload yyyy-mm-ddThh:mm:ss.sssZ
type successfully?
First you need to convert your string dates into a valid date time format (yyyy-mm-dd hh:mm:ss
).
With the help of STR_TO_DATE()
and DATE_FORMAT()
functions you can convert those date strings into the above desired format.
Now you can safely change/modify the datatype to timestamp/datetime.
Here's a demonstration:
Convert string dates into valid date format:
Create table yourtable(
id INT primary key AUTO_INCREMENT,
start varchar(50)
);
INSERT INTO yourtable(start) VALUES('1901-02-03T05:30:00.000Z');
UPDATE yourtable
SET start = DATE_FORMAT(STR_TO_DATE(start,'%Y-%m-%dT%H:%i:%s.000Z'),'%Y-%m-%d %H:%i:%s');
Change the datatype:
ALTER TABLE yourtable MODIFY COLUMN start datetime;