开发者

how to keep the datetime format from csv to mysql database when importing data?

I have a csv file where I changed th开发者_高级运维e initial datetime format:

  • from m/d/yyyy h:mm (6/15/2011 5:26:00 PM)
  • to yyyy-dd-mm h:mm (2011-15-06 17:26)

This was done in order to avoid 0000-00-00 as datetime value in MySQL database when importing data from that csv to MySQL.

This did not fix the problem. I still found 0000-00-00 as datetime value in my database.

To fix the problem, I first created the database in mysql (before importing the data from the csv file), and I used Datetime type in order to keep the values of date and time from that csv file.

Did I forget something? or is there any better way to fix that problem?


You might be having this problem because you aren't putting your dates in quotes. This won't work

INSERT INTO some_table 2011-07-12;

but this will

INSERT INTO some_table "2011-07-12";

Try editing one of the rows in your CSV file to put the date in quotes and see if that one gets read in properly.


try change day/month 2011-15-06---->2011-06-15 ;) and look at zeros may be it 00-00-0000 not 0000-00-00


how to keep the datetime format from csv to mysql database when importing data?

you can change the date format in the csv to format '2005-03-15' as shown in above image. Also, in the database table use 'date' or 'datetime' (based on requirement). On file import, you should see correct datetime field.

how to keep the datetime format from csv to mysql database when importing data?

This should solve this issue.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜