Mysql datetime format add 10 minutes

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

Hi i have table with datetime variable. I was wondering if i can somehow change the datetime column to add 1O minutes to stored date. Perhaps some trigger has to be involved.

Thanks for help

回答1:

I like the INTERVAL expr unit notation. It feels more readable to me:

SELECT NOW(),        NOW() + INTERVAL 10 MINUTE;   +--------------------------------+-------------------------------+ |             NOW()              |  NOW() + INTERVAL 10 MINUTE   | +--------------------------------+-------------------------------+ | August, 12 2013 14:12:56+0000  | August, 12 2013 14:22:56+0000 | +--------------------------------+-------------------------------+ 

If you want to select existing rows and add 10 minutes to the result:

SELECT the_date + INTERVAL 10 MINUTE FROM tbl; 

If you want to alter existing rows stored in a table, you could use:

UPDATE tbl SET the_date = the_date + INTERVAL 10 MINUTE; 

If you want increase by force a value by 10 minutes while inserting, you need a trigger:

CREATE TRIGGER ins_future_date BEFORE INSERT ON tbl FOR EACH ROW   SET NEW.the_date = NEW.the_date + INTERVAL 10 MINUTE 


回答2:

add 10 minute in following way

       SELECT  ADDTIME(now(), '1000'); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!