// dates & times reference

SQL INTERVAL keyword in MySQL

MySQL spells durations as INTERVAL n unit (a keyword, count and unit name), usable in DATE_ADD, DATE_SUB and direct date arithmetic.

Categoria
Dates & times
Returns
keyword (yields a span)
In this category
115 of 121

Sintaxe

d + INTERVAL 7 DAY
INTERVAL '1-6' YEAR_MONTH

Each block is a separate form. The support table and the examples show which engine takes which.

Suporte a mecanismos

MotorSupportNotas
SQL Server Different name or syntax DATEADD(unit, n, d); unit as bare keyword too
PostgreSQL Different name or syntax INTERVAL '7 days' literal instead
MySQL Sim this form, the portable-in-MySQL spelling
SQLite Different name or syntax modifiers: date(d, '+7 days')
Oracle Different name or syntax INTERVAL '7' DAY literals or NUMTODSINTERVAL

Exemplos

MySQL

SELECT '2026-08-01' + INTERVAL 7 DAY;  -- 2026-08-08

MySQL

SELECT DATE_ADD('2026-08-01', INTERVAL '1-6' YEAR_MONTH);  -- 2028-02-01

MySQL

SELECT created_at + INTERVAL 90 MINUTE FROM jobs;

Bom saber

  • The unit list runs SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR plus compound pairs like DAY_HOUR, HOUR_MINUTE and YEAR_MONTH, whose values are quoted strings with any punctuation between the parts: INTERVAL '2:30' HOUR_MINUTE.
  • Direct arithmetic accepts it: SELECT '2026-08-01' + INTERVAL 7 DAY; no DATE_ADD call needed, and it beats string-plus-number coercion which does numeric addition.
  • WEEK is exactly 7 days here; MONTH clamps to month ends (Jan 31 + 1 MONTH gives Feb 28), the same month rule as DATE_ADD, because it is DATE_ADD.

Questions about INTERVAL n unit

Why does MySQL use INTERVAL 7 DAY instead of a literal?

MySQL reuses one keyword grammar for arithmetic units; the SQL-standard INTERVAL '7 days' literal form is not accepted there, the reverse of PostgreSQL.

What units exist?

MICROSECOND through YEAR, plus compound YEAR_MONTH, DAY_HOUR, DAY_MINUTE, DAY_SECOND, HOUR_MINUTE, HOUR_SECOND, MINUTE_SECOND and the *_MICROSECOND variants, each taking a quoted multi-part value.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.