Home  >  Article  >  Database  >  How to use compound INTERVAL units in MySQL?

How to use compound INTERVAL units in MySQL?

WBOY
WBOYforward
2023-09-05 16:33:021003browse

How to use compound INTERVAL units in MySQL?

#The compound INTERVAL unit keyword consists of two keywords separated by an underscore (_). In order to use them in MySQL, unit values ​​must be enclosed in single quotes and separated by spaces.

Example - The following query will add 2 years and 2 months to a 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)

The above is the detailed content of How to use compound INTERVAL units 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