Increment date/time value by second with MySQL query?

MySQLMySQLi Database

For this, use date_add() with interval command. Let us first create a table −

mysql> create table DemoTable1867
     (
     ArrivalTime datetime
     );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1867 values('2019-10-12 12:34:45');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1867 values('2019-10-12 10:04:15');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1867 values('2019-10-12 11:00:23');
Query OK, 1 row affected (0.00 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1867;

This will produce the following output −

+---------------------+
| ArrivalTime         |
+---------------------+
| 2019-10-12 12:34:45 |
| 2019-10-12 10:04:15 |
| 2019-10-12 11:00:23 |
+---------------------+
3 rows in set (0.00 sec)

Here is the query to increment date/time value by second with MySQL query −

mysql> select date_add(ArrivalTime, interval 5 second) from DemoTable1867;

This will produce the following output −

+------------------------------------------+
| date_add(ArrivalTime, interval 5 second) |
+------------------------------------------+
| 2019-10-12 12:34:50                      |
| 2019-10-12 10:04:20                      |
| 2019-10-12 11:00:28                      |
+------------------------------------------+
3 rows in set (0.00 sec)
raja
Published on 26-Dec-2019 07:21:06
Advertisements