Formatting strings into dates in mySQL
I am migrating 开发者_如何学运维an Access db to mySQL. I am receiving the tables as CSVs and using Excel to drop and format some columns. The dates are coming to me as m/d/yyyy and go as far back as 1702. Since Excel brilliantly won't format any date before 1900 I am going to have to transform them some other way. Now it would be super simple to write a PHP script to iterate over rows and use date('Y-m-d', strtotime($date))
but I was wondering if there was a function or functions in mySQL that would be the equivalent?
Try the STR_TO_DATE function. e.g.
SELECT STR_TO_DATE('4/1/1960', '%m/%d/%Y');
精彩评论