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 正确导入日期时间?
基础教程推荐
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 无法解决整理冲突 2021-01-01
