问题描述
我想将表的数据复制到另一个表中,但我对一列感到痛苦.
I want to copy data of table into another but I have a pain for a column.
表 A 有一列 DP 类型
VARCHAR(10)
保存日期值字符串格式为dd/MM/yyyy".
表B有一个类型DATE
的DC列,以Date格式保存日期值方式:'yyyy-MM-dd'.
Table B has a column DC of type DATE
holding date values in Date format this way: 'yyyy-MM-dd'.
如果我将列 DP 更改为键入 DATE,则其所有值都将转换为0000-00-00".如果我尝试直接复制,则会出现错误,阻止复制,因为 DP 值不会被识别为 DC 列中的 DATE 值.
If I alter the column DP to type DATE, then all its values will be converted to "0000-00-00".And if I try to copy directly, an error will raise preventing from copying because DP values will not be recognized as DATE values in column DC.
因此,要么找到一种方法,将 DP 值重新格式化为符合模式yyyy-MM-dd"的 DATE 值,然后在复制时复制或找到一些函数将法语日期转换为英语日期.
So either, find a way to reformat DP values to DATE values respecting the pattern 'yyyy-MM-dd' and then copy or find some function to convert the french date to english date while copying.
有人知道吗?问候!
推荐答案
STR_TO_DATE 函数可以为您处理.
STR_TO_DATE(`DP`, "%d/%m/%Y")
这篇关于如何重新格式化 MySQL 列的日期值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!