Add 11 days to current date in MySQL

MySQLMySQLi Database

Let us first create a table −

mysql> create table DemoTable1994
(
   ArrivalDate date
);
Query OK, 0 rows affected (5.33 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1994 values('2019-12-18');
Query OK, 1 row affected (0.47 sec)
mysql> insert into DemoTable1994 values('2019-12-19');
Query OK, 1 row affected (0.33 sec)
mysql> insert into DemoTable1994 values('2019-12-20');
Query OK, 1 row affected (0.49 sec)
mysql> insert into DemoTable1994 values('2019-12-25');
Query OK, 1 row affected (0.30 sec)
mysql> insert into DemoTable1994 values('2018-12-20');
Query OK, 1 row affected (1.42 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1994;

This will produce the following output −

+-------------+
| ArrivalDate |
+-------------+
| 2019-12-18  |
| 2019-12-19  |
| 2019-12-20  |
| 2019-12-25  |
| 2018-12-20  |
+-------------+
5 rows in set (0.00 sec)

Here is the query to add 11 days to current date MySQL −

mysql> select ArrivalDate,date_add(ArrivalDate,interval 11 Day) from DemoTable1994 where ArrivalDate=curdate();

This will produce the following output −

+-------------+---------------------------------------+
| ArrivalDate | date_add(ArrivalDate,interval 11 Day) |
+-------------+---------------------------------------+
| 2019-12-20  | 2019-12-31                            |
+-------------+---------------------------------------+
1 row in set (0.00 sec)
raja
Published on 02-Jan-2020 09:55:57
Advertisements