Set new delay time in a MySQL column


To set new delay time, use INTERVAL and update the column wth SETa clause and UPDATE command. Let us first create a table −

mysql> create table DemoTable
(
   DelayTime time
);
Query OK, 0 rows affected (1.21 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('11 :30 :10');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable values('12 :40 :00');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values('05 :45 :24');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('09 :00 :10');
Query OK, 1 row affected (0.18 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+------------+
| DelayTime  |
+------------+
| 11 :30 :10 |
| 12 :40 :00 |
| 05 :45 :24 |
| 09 :00 :10 |
+------------+
4 rows in set (0.00 sec)

Following is the query to set new delay time −

mysql> select date_add(DelayTime,interval 10 second) AS `NewDelayTime` from DemoTable;

This will produce the following output −

+--------------+
| NewDelayTime |
+--------------+
| 11 :30 :20   |
| 12 :40 :10   |
| 05 :45 :34   |
| 09 :00 :20   |
+--------------+
4 rows in set (0.00 sec)
raja
Published on 09-Oct-2019 14:47:27
Advertisements