
- 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
MySQL - Changing year of dates from 2020 to 2011?
You can change year of dates from 2020 to 2011 using SUBDATE() with INTERVAL of 9 year because there is a difference of 9 years between 2020 to 2011.
The syntax is as follows:
UPDATE yourTableName SET yourDateColumnName=SUBDATE(yourDateColumnName,INTERVAL 9 YEAR);
To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table ChangeYearFrom2020To2011 -> ( -> Id int NOT NULL AUTO_INCREMENT, -> ExpiryDate date, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.67 sec)
Insert some records in the table using insert command. The query to insert record is as follows:
mysql> insert into ChangeYearFrom2020To2011(ExpiryDate) values('2020-09-12'); Query OK, 1 row affected (0.19 sec) mysql> insert into ChangeYearFrom2020To2011(ExpiryDate) values('2020-12-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into ChangeYearFrom2020To2011(ExpiryDate) values('2020-01-29'); Query OK, 1 row affected (0.12 sec) mysql> insert into ChangeYearFrom2020To2011(ExpiryDate) values('2020-06-30'); Query OK, 1 row affected (0.19 sec) mysql> insert into ChangeYearFrom2020To2011(ExpiryDate) values('2020-12-31'); 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 ChangeYearFrom2020To2011;
The following is the output:
+----+------------+ | Id | ExpiryDate | +----+------------+ | 1 | 2020-09-12 | | 2 | 2020-12-21 | | 3 | 2020-01-29 | | 4 | 2020-06-30 | | 5 | 2020-12-31 | +----+------------+ 5 rows in set (0.00 sec)
Here is the query to change only year from 2020 to 2011:
mysql> update ChangeYearFrom2020To2011 -> set ExpiryDate=subdate(ExpiryDate,interval 9 year); Query OK, 5 rows affected (0.20 sec) Rows matched: 5 Changed: 5 Warnings: 0
We will now check all the records of the table once again. The query is as follows:
mysql> select *from ChangeYearFrom2020To2011;
The following is the output:
+----+------------+ | Id | ExpiryDate | +----+------------+ | 1 | 2011-09-12 | | 2 | 2011-12-21 | | 3 | 2011-01-29 | | 4 | 2011-06-30 | | 5 | 2011-12-31 | +----+------------+ 5 rows in set (0.00 sec)
- Related Articles
- How to select month and year from dates in MySQL?
- Changing year in MySQL date?
- How to find the day of the year from dates in R?
- Show date like 30-04-2020 instead of 2020-04-30 from MySQL database?
- Changing Column in MySQL from int to double?
- MySQL - changing table engine from innoDB to MyISAM?
- MySQL query to retrieve current date from a list of dates
- Java Program to Display Dates of Calendar Year in Different Format
- MySQL extract year from date format?
- Changing data type from date to date/time in MySQL?
- MySQL query to get the current date from the list of dates
- Get maximum date from a list of varchar dates in MySQL
- How to match dates by month and year only in Excel?
- In which format Year(2) or Year(4) MySQL will return the value of year from date ‘0000-00-00’?
- How do I generate days from the range of dates in MySQL?

Advertisements