Reputation: 203
In table have row datetime format 2013-01-01 01:01:01
I want update, date row and chenge all years from 2013
to 2012
My SQL UPDATE
ticketsSET YEAR(
t_date) = 2012 WHERE YEAR(
t_date) = 2013
But this not work , what is wrong ?
Upvotes: 0
Views: 3070
Reputation: 35323
SELECT date_Add(t_date - INTERVAL 1 YEAR), t_date
FROM your TableName where year(T_Date) =2013
Update yourTableName set t_date= date_Add(t_date-Interval 1) YEAR WHERE year(T_DATE) = 2013
You're method isn't working because your syntax is incorrect. Check the manual
exact link
Upvotes: 1
Reputation: 35018
What is wrong is that YEAR(t_date)
is the result of a function and you cannot update the result of a function.
You can do
update tickets
set t_date = date_add(t_date, interval -1 year)
where year(t_date) = 2013
Upvotes: 1