MySQL query to insert current date plus specific time?


You can use CONCAT() for this. The syntax is as follows −

insert into DemoTable values(concat(curdate(), ' yourSpecificTime’));

Let us first create a table −

mysql> create table DemoTable
   (
   ArrivalDate datetime
   );
Query OK, 0 rows affected (1.06 sec)

Insert some records in the table using insert command. We are adding the current date and time −

mysql> insert into DemoTable values(concat(curdate(), ' 10:20:05'));
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values(concat(curdate(), ' 12:05:00'));
Query OK, 1 row affected (0.17 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+---------------------+
| ArrivalDate         |
+---------------------+
| 2019-06-08 10:20:05 |
| 2019-06-08 12:05:00 |
+---------------------+
2 rows in set (0.00 sec)
raja
Published on 14-Jun-2019 11:21:11
Advertisements