Add 6 hours to now() function without using DATE_ADD() in MySQL?

MySQLMySQLi Database

Let us first create a table wherein one of the columns is with datetime. The query to create a table is as follows

mysql> create table Add6Hour
   - > (
   - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   - > ArrivalTime datetime
   - > );
Query OK, 0 rows affected (0.56 sec)

Insert some records in the table using insert command.

The query is as follows

mysql> insert into Add6Hour(ArrivalTime) values(now());
Query OK, 1 row affected (0.12 sec)

Display all records from the table using select statement.

The query is as follows

mysql> select *from Add6Hour;

The following is the output

+----+---------------------+
| Id | ArrivalTime         |
+----+---------------------+
|  1 | 2019-02-14 18:35:24 |
+----+---------------------+
1 row in set (0.00 sec)

Adding 6 hours to NOW()

mysql> select Id,ArrivalTime,( ArrivalTime+ INTERVAL 6 HOUR) AS AfterAdding6HourINNOW from Add6Hour;

The following is the output

+----+---------------------+-----------------------+
| Id | ArrivalTime         | AfterAdding6HourINNOW |
+----+---------------------+-----------------------+
|  1 | 2019-02-14 18:35:24 | 2019-02-15 00:35:24   |
+----+---------------------+-----------------------+
1 row in set (0.00 sec)
raja
Published on 19-Mar-2019 10:23:27
Advertisements