Lucas Eduardo Lucas Eduardo - 1 month ago 18
MySQL Question

VARCHAR to DATE - MySQL

I'm kinda new at database world and got stucked in my work with the every column in the database that supposed to be DATETIME, or TIMESTAMP, or anything related to date is VARCHAR(250) Ex.: 201610251557.

My question is, there is a way, to change the column to date, withou losing the values on it?

I already tried to change the column structure, but it changes every value to 0000-00-00 00-00.

Answer

Safest scenario is:

  1. add a new field with the correct type
  2. update data until new field is populated with appropriate data for all rows
  3. (optional) delete (or rename for archival purposes) old field
  4. (optional) rename new field to original field's name
Comments