Add 30 days to date in a MySQL table with arrival date records

MySQLMySQLi Database

Use INTERVAL to update the days for all the dates in a MySQL table column. Let us first create a table −

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

Insert some records in the table using insert command −

mysql> insert into DemoTable814 values('2018-12-02');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable814 values('2017-03-12');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable814 values('2019-12-23');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable814 values('2016-06-01');
Query OK, 1 row affected (0.32 sec)
mysql> insert into DemoTable814 values('2019-08-03');
Query OK, 1 row affected (0.20 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable814;

This will produce the following output −

+-------------+
| ArrivalDate |
+-------------+
| 2018-12-02  |
| 2017-03-12  |
| 2019-12-23  |
| 2016-06-01  |
| 2019-08-03  |
+-------------+
5 rows in set (0.00 sec)

Following is the query to add 30 days to date −

mysql> select ArrivalDate+ Interval 30 Day from DemoTable814;

This will produce the following output −

+------------------------------+
| ArrivalDate+ Interval 30 Day |
+------------------------------+
| 2019-01-01                   |
| 2017-04-11                   |
| 2020-01-22                   |
| 2016-07-01                   |
| 2019-09-02                   |
+------------------------------+
5 rows in set (0.05 sec)
raja
Published on 03-Sep-2019 14:42:00
Advertisements