How can we add day/s in the date stored in a column of MySQL table?


Two functions can be used for this purpose and in both the functions we need to provide column name as an argument along with INTERVAL keyword. The functions are as follows −

DATE_ADD() function

The syntax of this function is DATE_ADD(date, INTERVAL expression unit). It can be demonstrated by following the example which uses the data from table ‘collegedetail’ −

mysql> Select estb, DATE_ADD(estb, INTERVAL 10 DAY) from collegedetail;
+------------+---------------------------------+
| estb | DATE_ADD(estb, INTERVAL 10 DAY)       |
+------------+---------------------------------+
| 2010-05-01 | 2010-05-11                      |
| 1995-10-25 | 1995-11-04                      |
| 1994-09-25 | 1994-10-05                      |
| 2001-07-23 | 2001-08-02                      |
| 2010-07-30 | 2010-08-09                      |
+------------+---------------------------------+
5 rows in set (0.00 sec)

The above query added 10 days in the date stored in ‘estb’ column of ‘collegedetail’ table.

ADDDATE() function

The syntax of this function is ADDDATE(date, INTERVAL expression unit). It can be demonstrated by following the example which uses the data from table ‘collegedetail’ −

mysql> Select estb, ADDDATE(estb, INTERVAL 10 DAY) from collegedetail;
+------------+--------------------------------+
| estb       | ADDDATE(estb, INTERVAL 10 DAY) |
+------------+--------------------------------+
| 2010-05-01 | 2010-05-11                     |
| 1995-10-25 | 1995-11-04                     |
| 1994-09-25 | 1994-10-05                     |
| 2001-07-23 | 2001-08-02                     |
| 2010-07-30 | 2010-08-09                     |
+------------+--------------------------------+
5 rows in set (0.00 sec)

The above query added 10 days in the date stored in ‘estb’ column of ‘collegedetail’ table.

Updated on: 22-Jun-2020

104 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements