如何将MySQL列从VARCHAR更改为日期时间并同时转换数据? [英] How can I change a MySQL column from VARCHAR to date time and convert the data at the same time?

查看:271
本文介绍了如何将MySQL列从VARCHAR更改为日期时间并同时转换数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的数据集,其中有一个varchar列,其中包含一个不寻常的日期时间格式.

I have a large set of data with a varchar column which contains an unusual date time format.

如何同时转换6000多个行中的数据,然后转换列的类型?

How can I both convert the data in the 6000+ rows, and then convert the column's type?

我可以看到可以使用以下方式转换类型:

I can see that it's possible to convert the type with this:

ALTER TABLE <tblName> MODIFY <columnName> date time;

但是我看不到如何保留数据并同时对所有行执行此操作.

But I don't see how I can keep the data and do this for all rows at the same time.

我当前的日期示例是:

Mon, 23 Sep 2013 07:01:00 GMT

按照@Mihai的答案

Answer as per @Mihai

UPDATE rns
SET rns.`rns_pub_date` = STR_TO_DATE(rns_pub_date,"%a, %d %b %Y")

推荐答案

UPDATE `table`
SET `column` = STR_TO_DATE(`column`,'%Y-%m-%d')

根据需要调整格式.

这篇关于如何将MySQL列从VARCHAR更改为日期时间并同时转换数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆