Subtracts a time interval from a TIMESTAMP value. The inverse of TIMESTAMP_ADD.
TIMESTAMPDiperbarui: 13 Jun 2026TIMESTAMP_SUB(timestamp_expression, INTERVAL int64_expression timestamp_part)The starting TIMESTAMP value
The number of intervals to subtract
Interval unit: DAY, HOUR, MINUTE, SECOND, MILLISECOND, MICROSECOND
1 SELECT * 2 FROM `project.dataset.events` 3 WHERE event_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR);
Filter events that occurred within the last hour.
1 SELECT 2 TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), HOUR) as current_hour, 3 TIMESTAMP_SUB(TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), HOUR), INTERVAL 24 HOUR) as start_window;
Define a 24-hour rolling window starting from the current truncated hour.
Sudah paham TIMESTAMP_SUB? Latih langsung di browser
Latihan interaktif, langsung di browser.