- 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
How to change the date in a table with date records with MySQL?
Let’s say you need to change the date and add years. For this, use UPDATE command along with DATE_ADD(). Let us first create a table −
mysql> create table DemoTable1984 ( ShippingDate date ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1984 values('2014-01-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1984 values('2015-12-23'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1984 values('2017-10-31'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1984 values('2018-06-01'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1984;
This will produce the following output −
+--------------+ | ShippingDate | +--------------+ | 2014-01-11 | | 2015-12-23 | | 2017-10-31 | | 2018-06-01 | +--------------+ 4 rows in set (0.00 sec)
Here is the query to change the date −
mysql> update DemoTable1984 set ShippingDate=date_add(ShippingDate,interval 2 year); Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0
Let us check table records once again −
mysql> select * from DemoTable1984;
This will produce the following output −
+--------------+ | ShippingDate | +--------------+ | 2016-01-11 | | 2017-12-23 | | 2019-10-31 | | 2020-06-01 | +--------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to fetch the latest date from a table with date records
- Add 30 days to date in a MySQL table with arrival date records
- How to find last date from records with date values in MySQL?
- How to compare the first date and the last date from a MySQL column with date records?
- Filter dates from a table with DATE and NULL records in MySQL
- How to insert date record to the same table with different date formats with MySQL?
- How to change date format with DATE_FORMAT() in MySQL?
- MySQL query to select records with a particular date?
- How to insert DATE in MySQL table with TRIGGERS?
- Find the difference between current date and the date records from a MySQL table
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- MySQL queries to update date records with NULL values
- MySQL query to subtract date records with week day and display the weekday with records
- MySQL query to select records with a particular date and time?
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?

Advertisements