
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Multiple Intervals to DATE_ADD in MySQL
The current date and time is as follows −
mysql> select now();
Output
This will produce the following output −
+---------------------+ | now() | +---------------------+ | 2019-06-15 12:24:06 | +---------------------+ 1 row in set (0.00 sec)
Let us first create a table −
mysql> create table DemoTable ->( -> ArrivalDate datetime -> ); Query OK, 0 rows affected (1.15 sec)
Insert some records in the table using insert command. Here, we are adding multiple intervals to the DATE_ADD() method −
mysql> insert into DemoTable values(DATE_ADD(DATE_ADD(NOW(), INTERVAL 6 MONTH), INTERVAL 1 YEAR)); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(DATE_ADD(DATE_ADD(NOW(), INTERVAL 3 MONTH), INTERVAL 4 YEAR)); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+---------------------+ | ArrivalDate | +---------------------+ | 2020-12-15 12:23:39 | | 2023-09-15 12:23:48 | +---------------------+ 2 rows in set (0.00 sec)
Advertisements