How to subtract seconds from all the date records in a MySQL column?

MySQLMySQLi Database

Let us first create a table −

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

Insert some records in the table using insert command −

mysql> insert into DemoTable833 values('2019-01-10 12:40:50');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable833 values('2019-02-16 11:10:30');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable833 values('2018-03-17 10:00:10');
Query OK, 1 row affected (0.20 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable833;

This will produce the following output −

+---------------------+
| ArrivalTime         |
+---------------------+
| 2019-01-10 12:40:50 |
| 2019-02-16 11:10:30 |
| 2018-03-17 10:00:10 |
+---------------------+
3 rows in set (0.00 sec)

Following is the query to subtract seconds from a MySQL date −

mysql> select ArrivalTime-interval 10 SECOND from DemoTable833;

This will produce the following output −

+--------------------------------+
| ArrivalTime-interval 10 SECOND |
+--------------------------------+
| 2019-01-10 12:40:40            |
| 2019-02-16 11:10:20            |
| 2018-03-17 10:00:00            |
+--------------------------------+
3 rows in set (0.00 sec)
raja
Published on 03-Sep-2019 16:14:48
Advertisements