将MySQL日期时间格式添加10分钟?
使用DATE_ADD()将10分钟添加到日期时间格式。以下是语法-
select date_add(yourColumnName ,interval 10 minute) from yourTableName;
让我们首先创建一个表-
mysql> create table add10MinuteDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> DelayDatetime datetime -> );
以下是使用insert命令在表中插入记录的查询-
mysql> insert into add10MinuteDemo(DelayDatetime) values('2019-01-23 12:45:56'); mysql> insert into add10MinuteDemo(DelayDatetime) values('2019-03-25 10:30:23'); mysql> insert into add10MinuteDemo(DelayDatetime) values('2019-04-21 04:04:30');
以下是使用select语句显示表中所有记录的查询-
mysql> select * from add10MinuteDemo;
这将产生以下输出-
+----+---------------------+ | Id | DelayDatetime | +----+---------------------+ | 1 | 2019-01-23 12:45:56 | | 2 | 2019-03-25 10:30:23 | | 3 | 2019-04-21 04:04:30 | +----+---------------------+ 3 rows in set (0.00 sec)
以下是添加10分钟的查询-
mysql> select date_add(DelayDatetime,interval 10 minute) from add10MinuteDemo;
这将产生以下输出-
+--------------------------------------------+ | date_add(DelayDatetime,interval 10 minute) | +--------------------------------------------+ | 2019-01-23 12:55:56 | | 2019-03-25 10:40:23 | | 2019-04-21 04:14:30 | +--------------------------------------------+ 3 rows in set (0.00 sec)