A datetime expression is used to generate values of the datetime data type or perform operations on datetime values.
Syntax of date and time expressions
date_expr { + | - } INTERVAL expr date_unit
Common values of date_unit include:
DAY、WEEK、MONTH、QUARTER、YEARHOUR、MINUTE、SECOND、MICROSECOND- Compound units:
DAY_HOUR,DAY_MINUTE,DAY_second,HOUR_MINUTE,HOUR_SECOND,YEAR_MONTH, and so on.
For the complete list of date_unit, see the date_unit production rule in Expression syntax.
Usage instructions
date_exprcan be a column or expression of theDATE,DATETIME, orTIMESTAMPtype.INTERVAL expr date_unitspecifies a time interval.- When
date_expris added to or subtracted fromINTERVAL, the result is a new datetime value.
Examples
Add 7 days to the current date:
obclient> SELECT NOW() + INTERVAL 7 DAY;
+----------------------------+
| NOW() + INTERVAL 7 DAY |
+----------------------------+
| 2026-06-09 17:13:00 |
+----------------------------+
1 row in set
Subtract 1 month from the current date:
obclient> SELECT NOW() - INTERVAL 1 MONTH;
+----------------------------+
| NOW() - INTERVAL 1 MONTH |
+----------------------------+
| 2026-05-02 17:13:00 |
+----------------------------+
1 row in set
