开发者

mySql: convert date from Jan 01, 2000 to 2000-01-01

开发者 https://www.devze.com 2023-03-17 05:24 出处:网络
I am trying to \'normalize\' some data from a column that has two date formats, one like \"Mon dd, yyyy and another \"YYYY-mm-dd\". I would like to convert all of the first into the second format, and

I am trying to 'normalize' some data from a column that has two date formats, one like "Mon dd, yyyy and another "YYYY-mm-dd". I would like to convert all of the first into the second format, and then change the column type to date.

I imagine it is something like this:

UPDATE table SET 
`thedate` = DATE_FORMAT(`thedate`, '%Y-%m-%d')
WHERE `th开发者_C百科edate` LIKE '%,%'

but the DATE_FORMAT is the wrong function, I think.

Any ideas?

thanks.


I think I got it.

SELECT date_format( str_to_date( thedate, '%M %d, %Y' ) , '%Y-%m-%d' ) 
newdate, thedate 
FROM donor
WHERE `thedate` LIKE '%,%'
0

精彩评论

暂无评论...
验证码 换一张
取 消