How to use compound INTERVAL unit in MySQL?

MySQLMySQLi Database

Compound INTERVAL unit keywords are made up of two keywords and separated by an underscore (_). For using them in MySQL the unit values must be enclosed in single quotes and separated by space.

Example − Following query will add 2 years and 2 months in the date value.

mysql> Select timestamp('2017-10-22 04:05:36' + INTERVAL '2 2' year_month) AS'Date After 2 Years and 2 Months';
+---------------------------------+
| Date After 2 Years and 2 Months |
+---------------------------------+
| 2019-12-22 04:05:36             |
+---------------------------------+
1 row in set (0.00 sec)
raja
Published on 19-Feb-2018 15:33:17
Advertisements