
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 Days to Date in 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.
Advertisements