本文介绍了mysql datetime格式添加10分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有带datetime变量的表.我想知道是否可以以某种方式更改datetime列以将1O分钟添加到存储的日期.也许必须涉及一些触发因素.
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.
感谢帮助
推荐答案
我喜欢表示法.对我来说,它更具可读性:
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
这篇关于mysql datetime格式添加10分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!