Home >Database >Mysql Tutorial >How to use arithmetic operators (+, -, *, /) with unit values ​​of INTERVAL keyword in MySQL?

How to use arithmetic operators (+, -, *, /) with unit values ​​of INTERVAL keyword in MySQL?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBforward
2023-08-31 15:29:021023browse

如何在 MySQL 中将算术运算符(+、-、*、/)与 INTERVAL 关键字的单位值一起使用?

We can use arithmetic operators ( , -, *, /) with the unit value of the INTERVAL keyword, as follows -

Use 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 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 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 division sign (/)

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)

The above is the detailed content of How to use arithmetic operators (+, -, *, /) with unit values ​​of INTERVAL keyword in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete