how to make phpMyAdmin import datetime correctly from csv?(如何使 phpMyAdmin 从 csv 正确导入日期时间?)
问题描述
我收到了一个 csv 文件,其中包含客户数据库表的导出.其中两列是日期,在文件中它们的格式为 mm/dd/yyyy.
I've been provided a csv file which contains an export of a client's database table. Two of the columns are dates, and in the file they're formatted as mm/dd/yyyy.
ID | ActivateDate
-----------------
1 | 05/22/2010
2 | 10/01/2010
我需要将它们导入的 mySQL 数据库将这些列定义为日期时间,默认值为 null.当我在phpMyAdmin中使用导入功能时,它会将导入记录中的所有日期列设置为0000-00-00 00:00:00,而不管导入文件中是否有任何值.
Our mySQL database that I need to import them into has those columns defined as datetime, with a default value of null. When I use the import function in phpMyAdmin, it's setting all the date columns in the imported records to 0000-00-00 00:00:00, regardless of whether there's any value in the import file.
谁能告诉我需要做什么才能将数据库中的 ActivateDate 列设置为 2010-05-22 00:00:00 而不是 0000-00-00 00:00:00?
Can anyone tell me what I need to do to get the ActivateDate column in the database to be set to 2010-05-22 00:00:00 instead of 0000-00-00 00:00:00?
推荐答案
如果可能,我会先将这些值导入到 varchar 列 fake_column 中,然后将它们推送到真正的列 real_column 使用 STR_TO_DATE.
If at all possible, I'd import those values into a varchar column fake_column first, and then push them over into the real column real_columnusing STR_TO_DATE.
UPDATE tablename SET real_column = STR_TO_DATE(fake_column, '%m/%d/%Y');
参考构建格式字符串
这篇关于如何使 phpMyAdmin 从 csv 正确导入日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使 phpMyAdmin 从 csv 正确导入日期时间?
基础教程推荐
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
