
- 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
How can I use the arithmetic operators (+,-,*,/) with unit values of INTERVAL keyword in MySQL?
We can use arithmetic operators (+,-,*, /) with the unit values of INTERVAL keyword as follows −
Use of Addition (+)
mysql> Select date('2017-10-22' + INTERVAL 2+2 Year) AS 'Date After (2+2)Years'; +------------------------+ | Date After (2+2) Years | +------------------------+ | 2021-10-22 | +------------------------+ 1 row in set (0.00 sec)
Use of Subtraction (-)
mysql> Select date('2017-10-22' + INTERVAL 2-2 Year) AS 'Date After (2-2)Years'; +------------------------+ | Date After (2-2) Years | +------------------------+ | 2017-10-22 | +------------------------+ 1 row in set (0.00 sec)
Use of Multiplication (*)
mysql> Select date('2017-10-22' + INTERVAL 2*2 Year) AS 'Date After (2*2)Years'; +------------------------+ | Date After (2*2) Years | +------------------------+ | 2021-10-22 | +------------------------+ 1 row in set (0.00 sec)
Use of division (/)
mysql> Select date('2017-10-22' + INTERVAL 2/2 Year) AS 'Date After (2/2) Years'; +------------------------+ | Date After (2/2) Years | +------------------------+ | 2018-10-22 | +------------------------+ 1 row in set (0.00 sec)
- Related Articles
- What MySQL returns if I use enclosed set of unit values with INTERVAL keyword?
- How can I use INTERVAL keyword with MySQL NOW() and CURDATE() functions?
- What are the different unit values that can be used with MySQL INTERVAL keyword?
- How can I use MySQL INTERVAL keyword while extracting the part of the date?
- How MySQL behaves if I use INTERVAL keyword with an invalid date?
- How to use compound INTERVAL unit in MySQL?
- How can I use MySQL INTERVAL() function with a column of a table?
- How MySQL behaves when we use INTERVAL of time unit with CURDATE() function?
- Why in MySQL, we cannot use arithmetic operators like ‘=’, ‘
- Can we use INTERVAL keyword while inserting date records in a MySQL table?
- What MySQL returns if I write only one value in the enclosed set of unit values for compound INTERVAL unit?
- How MySQL performs date arithmetic with addition and subtraction operators?
- Can I use SUM() with IF() in MySQL?
- How can I use TIME_FORMAT() function to offload time/date values in MySQL?
- How can we use logical operators while creating MySQL views?

Advertisements