[英]Convert text column, with several formats, to date column in MySQL
I have a column, named 'ActionTime' with varchar entries of the following format, either: 我有一列名为“ ActionTime”,其中包含以下格式的varchar条目:
'14/02/2016 5:05'
or 要么
'14/02/2016 15:05'
I want to create a query that will return a new column with the values from ActionTime as a datetime format. 我想创建一个查询,该查询将以ActionTime的值作为日期时间格式返回一个新列。 I have:
我有:
UPDATE `test1`
SET `newcol` = str_to_date( `ActionTime` , '%d/%m/%Y %h:%i' );
which works assuming there aren't dates like '4/02/2016 15:05' but only like '14/02/2016 5:05'. 假设没有像“ 4/02/2016 15:05”之类的日期,而仅像“ 14/02/2016 5:05”之类的作品。
Can you think of a query to solve this? 您能想到一个查询来解决这个问题吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.