SUBTRACT()

All functions > DATE AND TIME > SUBTRACT()

Subtracts an interval from a timestamp or date, or returns the interval between two timestamps or two dates.

Signatures

Date and time subtraction

Returns: Timestamp after subtracting an interval, or the interval between two datetimes

SUBTRACT(minuend: TIMESTAMP or DATE, subtrahend: INTERVAL, TIMESTAMP, or DATE) → TIMESTAMP or INTERVAL
sql
ParameterTypeRequiredDescription
minuendTIMESTAMP or DATEYesTimestamp or date to subtract from
subtrahendINTERVAL, TIMESTAMP, or DATEYesInterval to subtract, or another timestamp/date whose difference is taken

Signature notes:

  • timestamp - interval or date - interval → TIMESTAMP
  • timestamp1 - timestamp2 or date1 - date2 → INTERVAL
  • Returns NULL if either operand is NULL

Related operators

Examples

SUBTRACT(...)

FeatureQL
SELECT
    f1 := SUBTRACT(10, 3) -- Function call
;
Result
f1 BIGINT
7

.SUBTRACT(...) — chained

FeatureQL
SELECT
    f1 := (10).SUBTRACT(3), -- Integer literal: use parentheses for `.SUBTRACT` on a BIGINT value
    f2 := 10.0.SUBTRACT(3) -- Decimal base: chain without extra parentheses
;
Result
f1 BIGINTf2 VARCHAR
77.0

Date and time

FeatureQL
SELECT
    f1 := TIMESTAMP '2021-01-02'.SUBTRACT(INTERVAL '1 DAY'), -- Chained subtract on a timestamp
    f2 := TIMESTAMP '2021-01-02'.SUBTRACT(TIMESTAMP '2021-01-01') -- Interval between two timestamps via chained call
;
Result
f1 TIMESTAMPf2 VARCHAR
2021-01-01T00:00:001 days

Edge cases

FeatureQL
SELECT
    f1 := SUBTRACT(5, 5), -- Equal operands
    f2 := SUBTRACT(1, 7), -- Negative result
    f3 := SUBTRACT(0, -5) -- Subtracting a negative
;
Result
f1 BIGINTf2 BIGINTf3 BIGINT
0-65

Last update at: 2026/05/26 17:22:09