开发者

Mysql how to get new date from a column date?

开发者 https://www.devze.com 2023-02-28 07:17 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号