我有YYYY-MM-DD格式的大量日期
但我整年都在2020-MM-DD
我想将其更改为2011-MM-DD
我怎样才能做到这一点?
答案 0 :(得分:13)
UPDATE YourTable
SET YourDateColumn = SUBDATE(YourDateColumn, INTERVAL 9 YEAR);
答案 1 :(得分:5)
USE ADDDATE(old_date, INTERVAL -9 YEAR)
答案 2 :(得分:2)
UPDATE YourTable
SET YourDateColumn = ADDDATE(YourDateColumn, INTERVAL 1 YEAR)
WHERE YourDateColumn >= '2010-01-01'
AND YourDateColumn <= '2010-12-31';
如果您的表格在日期字段中没有索引,您可以放弃:
UPDATE YourTable
SET YourDateColumn = ADDDATE(YourDateColumn, INTERVAL 1 YEAR)
WHERE YEAR(YourDateColumn) = 2010;
要确定2020年的日期问题,请到2021运行:
UPDATE YourTable
SET YourDateColumn = ADDDATE(YourDateColumn, INTERVAL -1 YEAR)
WHERE YEAR(YourDateColumn) = 2021;
BTW因为我复制了Joe Stefanelli的原始代码,为他+1 +1!