- 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 a single year to all the date records in a MySQL table column
Let us first create a table −
mysql> create table DemoTable -> ( -> JoiningDate datetime -> ); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2015-01-21'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2017-04-02'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('2018-12-31'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------------+ | JoiningDate | +---------------------+ | 2015-01-21 00:00:00 | | 2017-04-02 00:00:00 | | 2018-12-31 00:00:00 | +---------------------+ 3 rows in set (0.00 sec)
Here is the query to implement DATE_ADD() and add a single year −
mysql> select date_add(JoiningDate, interval 1 year) from DemoTable;
This will produce the following output −
+----------------------------------------+ | date_add(JoiningDate, interval 1 year) | +----------------------------------------+ | 2016-01-21 00:00:00 | | 2018-04-02 00:00:00 | | 2019-12-31 00:00:00 | +----------------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Add 30 days to date in a MySQL table with arrival date records
- How to subtract seconds from all the date records in a MySQL column?
- How to add a year and two days to a date with a single MySQL query?
- Display month names and year from a column with date records with MySQL
- A single MySQL query to insert records (not all) in the second table from the first table
- How to change the date in a table with date records with MySQL?
- Insert all the values in a table with a single MySQL query separating records by comma
- MySQL query to fetch the latest date from a table with date records
- How can we add a time interval to date stored in a column of MySQL table?
- Delete all the records from a MySQL table?
- Delete all records from a table in MySQL?
- Add a new column and index to an existing table with ALTER in a single MySQL query?
- How to delete all the duplicate records in a MySQL table?
- How to add a column in a table in MySQL?
- Best way to update a single column in a MySQL table?

Advertisements