
- 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
Update MySQL date and increment by one Year?
You can use in-built function date_add() from MySQL. The syntax is as follows −
UPDATE yourTableName SET yourDateColumnName=DATE_ADD(yourDateColumnName,interval 1 year);
To understand the above syntax, let us first create a table. The query to create a table is as follows −
mysql> create table UpdateDate -> ( -> Id int, -> DueDate datetime -> ); Query OK, 0 rows affected (0.76 sec)
Insert some records in the table using insert command. The query to insert record is as follows −
mysql> insert into UpdateDate values(1001,'2012-5-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into UpdateDate values(1002,'2013-8-2'); Query OK, 1 row affected (0.17 sec) mysql> insert into UpdateDate values(1003,'2014-2-27'); Query OK, 1 row affected (0.10 sec) mysql> insert into UpdateDate values(1004,'2016-11-1'); Query OK, 1 row affected (0.18 sec) mysql> insert into UpdateDate values(1005,'2017-12-24'); Query OK, 1 row affected (0.12 sec)
Let us now display all records from the table using select command. The query is as follows −
mysql> select *from UpdateDate;
Output
+------+---------------------+ | Id | DueDate | +------+---------------------+ | 1001 | 2012-05-21 00:00:00 | | 1002 | 2013-08-02 00:00:00 | | 1003 | 2014-02-27 00:00:00 | | 1004 | 2016-11-01 00:00:00 | | 1005 | 2017-12-24 00:00:00 | +------+---------------------+ 5 rows in set (0.00 sec)
Here is the query that can be used to update date with 1 year using date_add() and interval. The query is as follows −
mysql> update UpdateDate set DueDate=date_add(DueDate,interval 1 year); Query OK, 5 rows affected (0.15 sec) Rows matched: 5 Changed: 5 Warnings: 0
Check the table using select command. The query is as follows −
mysql> select *from UpdateDate;
Output
+------+---------------------+ | Id | DueDate | +------+---------------------+ | 1001 | 2013-05-21 00:00:00 | | 1002 | 2014-08-02 00:00:00 | | 1003 | 2015-02-27 00:00:00 | | 1004 | 2017-11-01 00:00:00 | | 1005 | 2018-12-24 00:00:00 | +------+---------------------+ 5 rows in set (0.00 sec)
Look at the above sample output, all values have been updated. If you want to update a particular date time then use the where condition.
- Related Articles
- Increment date/time value by second with MySQL query?
- Update MySQL table column by matching date using date() function?
- How to perform Increment in MySQL Update?
- Changing year in MySQL date?
- MySQL extract year from date format?
- Format date in MySQL to return MonthName and Year?
- MySQL query to fetch date with year and month?
- Format MySQL date and convert to year-month-day
- How can I update and increment two fields in one command in MongoDB?
- Get beginning and end date from a specific year in MySQL
- MySQL query to update only month in date?
- How to update the date format in MySQL?
- How to update a MySQL date type column?
- MySQL increment a database field by 1?
- Update the date and time values while inserting them in MySQL

Advertisements