INTERVAL is both a data type and a literal that encodes a duration such as 3 days, 2 hours 15 minutes, or 1 year 6 months. It allows arithmetic on DATE, TIME, and TIMESTAMP columns without manually converting units. In most engines, an INTERVAL literal is written in quotes, paired with a unit keyword (for example, INTERVAL '7 day'). The engine converts that literal to its internal interval type and supports addition, subtraction, comparisons, casting, and storage. Two styles exist: year-to-month intervals (years, months) and day-to-second intervals (days down to fractional seconds). Precision and leading field specifications are optional but let you trim storage and validate range boundaries. Caveats: not all dialects store INTERVAL columns natively; some only allow literals in expressions. Mixed-type arithmetic (such as adding a year-to-month interval to a day-to-second interval) is disallowed. Always quote the value portion, ensure the unit is valid for the dialect, and prefer explicit CAST for portability.
quantity
(numeric) - the length of timeunit
(keyword) - time unit such as SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEARfield_to
(keyword) - optional ending field (e.g., YEAR TO MONTH, DAY TO SECOND)precision
(integer) - optional number of digits for leading field or fractional secondsDATE, TIME, TIMESTAMP, DATEADD, DATEDIFF, CAST, EXTRACT
SQL-92
Typical units are SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, and YEAR. Availability varies by dialect.
Yes. Define a column such as duration INTERVAL DAY TO SECOND. Some databases (e.g., MySQL) only allow expressions, not storage.
Simply subtract: end_ts - start_ts returns an INTERVAL (or numeric milliseconds in some dialects).
Yes. The INTERVAL data type and literals were introduced in SQL-92, though implementation details differ across vendors.