Raba_Ababa
Raba_Ababa

Reputation: 83

Change data format in existing field in mysql

In my db I have column in which there is about 1k~ records. All records have name field in which is overwrite also data. For eg. "name 7/24/2006". I need to change format mm/dd/yyyy to dd/mm/yyyy. Correctly it should be 24/07/2006. I tried to add this function: https://techras.wordpress.com/2011/06/02/regex-replace-for-mysql/ and run

SELECT regex_replace('(\d+)\/(\d+)\/(\d+)$','$2/$1/$3',column_name`) `column_name` 
FROM` `table_name` 

but it doesn't work. Any ideas how to fix it?

Upvotes: 0

Views: 51

Answers (1)

Mike Robinson
Mike Robinson

Reputation: 8995

You should be storing date values as true date-typed fields in MySQL. When you do this, you can view the date in whatever "output format" you like. (Or, several different ones.) This simply presents the date in a different way: it has no effect on the stored value itself.

Upvotes: 1

Related Questions