Home > Software engineering >  Moving data from datetime column to date column
Moving data from datetime column to date column

Time:11-10

In MySQL, I have a column with the datetime data type and I would like to transfer the data into a column with the date datatype. My goal is to have a new column that only containes the date without the time. I have already created a new column with the date data type but I don't know how to most efficiently transfer the data from one column to the other. Also, would I run into compatibility issues trying to transfer datetime data into a date column?

CodePudding user response:

Mysql auto converts to the date format if you transfer the date but you could use DATE(datetime) as format

UPDATE table SET dateColumn = DATE(dateTimeColumn);

So dateColumn is the new column here and this is not going to give compatibility issues.

  • Related