How to add time in a MySQL column set with type DATETIME?

MySQLMySQLi Database

To add time to datetime, use ADDTIME() function in MySQL. Let us first create a table −

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

Insert some records in the table using insert command −

mysql> insert into DemoTable1848 values('2019-10-11 12:30:45');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1848 values('2019-01-12 10:00:00');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1848 values('2019-12-03 17:30:00');
Query OK, 1 row affected (0.00 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1848;

This will produce the following output −

+---------------------+
| ShippingDate        |
+---------------------+
| 2019-10-11 12:30:45 |
| 2019-01-12 10:00:00 |
| 2019-12-03 17:30:00 |
+---------------------+
3 rows in set (0.00 sec)

Here is the query to add time −

mysql> select addtime(ShippingDate,'4:40') from DemoTable1848;

This will produce the following output −

+------------------------------+
| addtime(ShippingDate,'4:40') |
+------------------------------+
| 2019-10-11 17:10:45          |
| 2019-01-12 14:40:00          |
| 2019-12-03 22:10:00          |
+------------------------------+
3 rows in set (0.00 sec)
raja
Published on 26-Dec-2019 10:53:48
Advertisements