I have a table with a column date but it is stored as text.
Now I need to extract data based on date and I'm thinking I need to alter the column type to datetime, but how can I do that without losing data? My text records are in format dd-MM-YYYY hh:mm
If I just change the column type the data I lose all data (it is filled with zeros).
UPDATE `table`
SET `column` = STR_TO_DATE(`column`,'%d-%M-%Y %h:%i')
Just change the format to what you have,in case that is not correct.
Formats
SQL fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With