
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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.
- Related Articles
- How can we add a time interval to date stored in a column of MySQL table?
- How can we modify column/s of MySQL table?
- How can we insert current date automatically in a column of MySQL table?
- How can we alter table to add MySQL stored GENERATED COLUMNS?
- Can we add a column to a table from another table in MySQL?
- How can we apply BIT_LENGTH() function on the column/s of MySQL table?
- How to add a day to the date in MySQL?
- How can we fetch month and day from a given date in MySQL?
- How can we see the metadata of a view(s) stored in a particular MySQL database?
- How can we put comments in a column of existing MySQL table?
- How to add 1 day to the date in MySQL?
- How can we remove a column from MySQL table?
- How can we add values into the columns of a MySQL table?
- How can we create a new MySQL table by selecting specific column/s from another existing table?
- How can we change the data type of the column in MySQL table?

Advertisements