0

I have a database with a column 'Date'.

At first, the person whom setup the database, he wrongly set the column Type to varchar(9).

The date's are 01-01-2012 (10 Characters), thus on every single date is missing the last number.

enter image description here

Is it possible now to replace all 201 with 2012 using a MySQL Query?

Thanks

1
  • 1
    Why don't you use a DATE column type for that? Commented Nov 13, 2012 at 14:39

2 Answers 2

4
UPDATE tableName
SET columnName = REPLACE(columnName, '201', '2012')

OR

UPDATE tableName
SET columnName = CONCAT(columnName, '2')
Sign up to request clarification or add additional context in comments.

1 Comment

CONCAT adds a value at the end?
0

First increase the table size to varchar(10). Then

UPDATE tableName
SET columnName = REPLACE(columnName, '201', '2012')   

3 Comments

Im using phpMyAdmin. I think I need to use `` ? UPDATE Fuelconsumption SET date = REPLACE(date, '201', '2012')
you will only use backtick if your column name is a reserved keyword or has space on it, hello world
@jQuerybeast date isn't a reserved word in mysql, so no escaping needed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.