Add10 minutes to MySQL datetime format?

MySQLMySQLi Database

Use DATE_ADD() to add 10 minutes to datetime format. Following is the syntax −

select date_add(yourColumnName ,interval 10 minute) from yourTableName;

Let us first create a table −

mysql> create table add10MinuteDemo
   -> (
   -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> DelayDatetime datetime
   -> );
Query OK, 0 rows affected (0.83 sec)

Following is the query to insert records in the table using insert command −

mysql> insert into add10MinuteDemo(DelayDatetime) values('2019-01-23 12:45:56');
Query OK, 1 row affected (0.16 sec)
mysql> insert into add10MinuteDemo(DelayDatetime) values('2019-03-25 10:30:23');
Query OK, 1 row affected (0.19 sec)
mysql> insert into add10MinuteDemo(DelayDatetime) values('2019-04-21 04:04:30');
Query OK, 1 row affected (0.19 sec)

Following is the query to display all records from the table using select statement −

mysql> select * from add10MinuteDemo;

This will produce the following output −

+----+---------------------+
| 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)

Following is the query to add 10 minutes −

mysql> select date_add(DelayDatetime,interval 10 minute) from add10MinuteDemo;

This will produce the following output −

+--------------------------------------------+
| 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)
raja
Published on 16-Apr-2019 13:43:58
Advertisements