- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 30 days to a value in a MySQL table?
To add 30 days to a value in the table, you can use ADDDATE() function with UPDATE command. The syntax is as follows:
UPDATE yourTableName SET yourDateColumnName=ADDDATE(yourDateColumnName,INTERVAL 30 DAY);
To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table Add30DayDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> ShippingDate date, -> PRIMARY KEY(ID) -> ); Query OK, 0 rows affected (0.76 sec)
Insert some records in the table using insert command. The query is as follows:
mysql> insert into Add30DayDemo(ShippingDate) values('2019-02-04'); Query OK, 1 row affected (0.20 sec) mysql> insert into Add30DayDemo(ShippingDate) values('2018-11-15'); Query OK, 1 row affected (0.18 sec) mysql> insert into Add30DayDemo(ShippingDate) values('2013-05-18'); Query OK, 1 row affected (0.15 sec) mysql> insert into Add30DayDemo(ShippingDate) values('2017-08-25'); Query OK, 1 row affected (0.20 sec) mysql> insert into Add30DayDemo(ShippingDate) values('2016-03-01'); Query OK, 1 row affected (0.12 sec) mysql> insert into Add30DayDemo(ShippingDate) values('2015-09-03'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement. The query is as follows:
mysql> select *from Add30DayDemo;
The following is the output:
+----+--------------+ | Id | ShippingDate | +----+--------------+ | 1 | 2019-02-04 | | 2 | 2018-11-15 | | 3 | 2013-05-18 | | 4 | 2017-08-25 | | 5 | 2016-03-01 | | 6 | 2015-09-03 | +----+--------------+ 6 rows in set (0.00 sec)
Here is the query to add 30 days value in a table using DATEADD():
mysql> update Add30DayDemo -> SET ShippingDate=ADDDATE(ShippingDate,INTERVAL 30 DAY); Query OK, 6 rows affected (0.44 sec) Rows matched: 6 Changed: 6 Warnings: 0
Now check the table records once again. The query is as follows:
mysql> select *from Add30DayDemo;
The following is the output with the updated date:
+----+--------------+ | Id | ShippingDate | +----+--------------+ | 1 | 2019-03-06 | | 2 | 2018-12-15 | | 3 | 2013-06-17 | | 4 | 2017-09-24 | | 5 | 2016-03-31 | | 6 | 2015-10-03 | +----+--------------+ 6 rows in set (0.00 sec)
- Related Articles
- Add 30 days to date in a MySQL table with arrival date records
- MySQL add days to a date?
- MySQL Datetime to add days?
- How to add a column in a table in MySQL?
- Add 11 days to current date in MySQL
- Can we add a column to a table from another table in MySQL?
- How to add a column to a MySQL table in Python?
- MySQL query to delete a DATE older than 30 days from another date?
- MySQL query to add days with interval of 45 days and display the output in a new column
- ALTER TABLE to add a composite primary key in MySQL?
- How to add a year and two days to a date with a single MySQL query?
- How to subtract 30 days from the current datetime in MySQL?
- How to add some days to str_to_date() MySQL function?
- Display dates after NOW() + 10 days from a MySQL table?
- How do I add a check constraint to a table in MySQL?

Advertisements