开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜