How to use compound INTERVAL unit in MySQL?


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)

Updated on: 20-Jun-2020

90 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements