Reputation: 113
I have a varchar
type column in a database where i am inserting a date in this format Y-MM-DD
but now I am trying to change datatype of the column to timestamp
but the problem is I have some data in Y/MM/DD
this format from id 941
to so on. how can i remove slashes /
to hyphens -
so i can only be able to change datatype to timestamp
update tablename set created_at = substring_index(created_at,'-',2)
This query is completely wrong but know only this/
Upvotes: 0
Views: 1270
Reputation: 119
As I understood, you want to update all the values of the field created_at
, and replace the "/" with "-".
To achieve this, you can use this :
UPDATE tablename SET created_at = REPLACE(created_at, "/", "-");
You can check the following link for more information about the function REPLACE()
in MySQL: MySQL REPLACE() Function.
Hope this helps!
Upvotes: 2