views:

47

answers:

5

I have a fairly large number of rows where a datetime field is stored such as:

0010-01-03 00:00:00

But, I need it to be:

2010-01-03 00:00:00

Any suggestions on how to mass change rows from 0010 to 2010?

A: 
UPDATE table
SET field = '2010-01-03 00:00:00'
WHERE field = '0010-01-03 00:00:00'

Without more information, this is the only real answer I can give.

Slokun
Thanks for fast response. Yes, of course I could run this update for the one row that matches. But, there are many, many more with different months and days.
Todd M
A: 
UPDATE mytable SET mytimefield = mytimefield + INTERVAL '2000 years' where mytimefield < now() - INTERVAL '15 YEAR';

Not sure if that's the exact syntax for MySQL. It might be

UPDATE mytable SET mytimefield = DATE_ADD(mytimefield, INTERVAL 2000 YEAR) mytimefield < DATE_SUB(now(), INTERVAL 15 YEAR);
Paul Tomblin
Cool, and this won't update the correct 2010 years to 4010?
Todd M
You didn't mention correct rows. Let me fix that.
Paul Tomblin
I'll give it shot later tonight. Thanks!
Todd M
A: 

Add 2000 into year.

Svisstack
+2  A: 

Hi, try this:

UPDATE table SET field = field + INTERVAL 2000 year;

Take a look on MySQL Date and Time Functions . =]

André Gadonski
A: 

You could do something like this :

UPDATE table SET date = date_add(date, INTERVAL 2000 YEAR) WHERE YEAR(date) < 11;

If you have years like '0099' :

UPDATE table SET date = date_add(date, INTERVAL 1900 YEAR) WHERE YEAR(date) > 10 AND YEAR(date) < 100;
elblanco