- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add 6 hours to now() function without using DATE_ADD() in MySQL?
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)
Advertisements