Home » excel » sql – Formatting strings into dates in mySQL

sql – Formatting strings into dates in mySQL

Posted by: admin May 14, 2020 Leave a comment

Questions:

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?

How to&Answers:

Try the STR_TO_DATE function. e.g.

SELECT STR_TO_DATE(‘4/1/1960’, ‘%m/%d/%Y’);