SUBTRACT
All functions > DATE AND TIME > SUBTRACT
Returns difference between two dates or date and interval.
Signatures
Temporal subtraction
Returns: Timestamp after subtracting the interval
SUBTRACT(timestamp: TIMESTAMP, interval: INTERVAL) → TIMESTAMP sql
| Parameter | Type | Required | Description |
|---|---|---|---|
timestamp | TIMESTAMP | Yes | Timestamp to subtract from |
interval | INTERVAL | Yes | Interval to subtract |
With:
T: Custom types: TIMESTAMP | INTERVAL
Temporal difference
Returns: Interval between the two dates/timestamps
SUBTRACT(timestamp1: TIMESTAMP, timestamp2: TIMESTAMP) → INTERVAL sql
| Parameter | Type | Required | Description |
|---|---|---|---|
timestamp1 | TIMESTAMP | Yes | Timestamp to subtract from |
timestamp2 | TIMESTAMP | Yes | Timestamp to subtract |
With:
T: Any timestamp type
Notes
- For temporal types, supports subtracting intervals and calculating differences
- Returns NULL if either operand is NULL
- Order matters:
SUBTRACT(a, b)≠SUBTRACT(b, a) - Operator form:
number1 - number2