Change Date Format on Import to MySQL from CSV File

You have a .csv file with a date column that is formatted like this:  12/1/2015 (‘m/d/Y’).

You need to import it into a MySQL database DATE field named “my_dates”.

A straight import will result in all your dates showing up as ‘0000-00-00’, because MySQL uses the format ‘Y-m-d’, and won’t translate it natively.

Here’s the solution:

Create a VARCHAR field named “my_text_dates” in the database, and import the dates there.

Then, run this query:

Then, just delete the “my_text_dates” field, and you’re all set!

NOTE: the ‘%m/%d/%Y’ portion of the update statement needs to match exactly the format of your text date field.

Comments are closed.