且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将多种日期时间格式转换为单个 mysql 日期时间格式

更新时间:2023-02-03 19:05:06

为此,您需要使用 str_to_date().首先,修复 date_proper 列,使其成为 datetime.格式应该在输入和输出上处理.日期的正确存储是使用原生格式:

You need to use str_to_date() for this. First, fix the date_proper column so it is a datetime. Formats should be handled on input and output. The proper storage for dates is using native formats:

alter table modify date_proper datetime;

然后您可以更新值:

update t
    date_proper = (case when format < '6340'
                        then str_to_date(concat(year(now), ' ', col), '%Y %b %d - %h:%i %p'
                        else str_to_date(substr(col, 5), '%b %d, %Y %h:%i:%s %p'
                   end);