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(timestamp1: TIMESTAMP or DATE, timestamp2: INTERVAL, TIMESTAMP, or DATE) → TIMESTAMP or INTERVAL sql
| Parameter | Type | Required | Description |
|---|---|---|---|
timestamp1 | TIMESTAMP or DATE | Yes | Timestamp or date to subtract from |
timestamp2 | INTERVAL, TIMESTAMP, or DATE | Yes | Interval to subtract, or another timestamp/date whose difference is taken |
Signature notes:
timestamp - intervalordate - interval→ TIMESTAMPtimestamp1 - timestamp2ordate1 - date2→ INTERVAL- Returns NULL if either operand is NULL
Related operators
Examples
SUBTRACT(...)
FeatureQL
SELECT
-- Function call
f1 := SUBTRACT(10, 3)
;Result
| f1 BIGINT |
|---|
| 7 |
.SUBTRACT(...) — chained
FeatureQL
SELECT
-- Integer literal: use parentheses for `.SUBTRACT` on a BIGINT value
f1 := (10).SUBTRACT(3),
-- Decimal base: chain without extra parentheses
f2 := 10.0.SUBTRACT(3)
;Result
| f1 BIGINT | f2 DECIMAL |
|---|---|
| 7 | 7.0 |
Date and time
FeatureQL
SELECT
-- Chained subtract on a timestamp
f1 := TIMESTAMP '2021-01-02'.SUBTRACT(INTERVAL '1 DAY')
;Result
| f1 TIMESTAMP |
|---|
| 2021-01-01T00:00:00 |
Edge cases
FeatureQL
SELECT
-- Interval between two timestamps via chained call
f1 := TIMESTAMP '2021-01-02'.SUBTRACT(TIMESTAMP '2021-01-01')
;Result
| f1 VARCHAR |
|---|
| 1 days |