Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
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) Advertisements
