在数据库级别将varchar列转换为mysql中的日期 [英] Convert varchar column to date in mysql at database level
本文介绍了在数据库级别将varchar列转换为mysql中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只有一列date1
,它是 varchar 类型
我希望此列为date
类型.
我尝试更改字段,但所有日期都转换为0000-00-00
.
格式为dd-mm-yyyy
,但为 varchar .
I have one column date1
which is varchar type
I want this column to date
type.
I tried changing field but all date is converted to 0000-00-00
.
format is dd-mm-yyyy
but in varchar.
如何使用sql查询或类似的方法在数据库级别转换相同的日期格式但转换为日期格式?
How can I convert the same date format but with date format using sql queries or similar but at database level ?
推荐答案
UPDATE `table`
SET `column` = str_to_date( `column`, '%d-%m-%Y' );
有关 STR_TO_DATE 的更多信息功能.
由于列名是date1
,因此您可以在上述语法中将column
替换为date1
,并且代码应为:
Since your column name is date1
, you can replace column
with date1
in the above syntax, and the code shall be:
UPDATE `table`
SET `date1` = str_to_date( `date1`, '%d-%m-%Y' );
这篇关于在数据库级别将varchar列转换为mysql中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文