更新时间:2023-02-12 09:36:46
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 |
+--------------------------------+-------------------------------+
如果要选择现有行并在结果中添加10分钟:
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;
如果要在插入时通过 force 值增加10分钟,则需要一个触发器:
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