Hi I have a table that have timestamp column. I want to update a date with 1 second before of it. How can I do that?
Exp:
name | date ibrahim | 2011-04-14 03:35:05 blabla | 2011-04-14 03:00:00 . . .
After update, date of second row should be "2011-04-14 02:59:59" etc.
edit:
answer is开发者_如何转开发UPDATE table SET date=DATE_SUB(date,INTERVAL 1 SECOND) WHERE name="blabla";
Use DATE_SUB(date,INTERVAL expr unit) function.
or
update `table` set date_date = date_date - INTERVAL 1 SECOND;
update table set `date`= DATE_SUB(`date`,INTERVAL 1 SECOND)
UPDATED
To put the actual column name in query
Side Note: Your column name date
is mysql reserved word so you have to put it in backticks `` otherwise mysql will produce syntax error as I did in above query.
精彩评论