Search code examples
sqlgoogle-bigquery

How to get TIMESTAMP of 15 minutes ago using BigQuery?


Found this but this doesn't run on standard SQL

I tried to do:

WHERE datew > DATE_SUB(CURRENT_TIMESTAMP(),INTERVAL 5 DAY )

But this doesn't work. According to the docs DATE_SUB supports only

DAY
WEEK. Equivalent to 7 DAYs.
MONTH
QUARTER
YEAR

How can I get current time stamp - 15 minutes on standard SQL with BigQuery?


Solution

  • Check out timestamp_sub() function.

    How to use it:

    SELECT
    CURRENT_TIMESTAMP() AS now, 
    TIMESTAMP_SUB(CURRENT_TIMESTAMP(),INTERVAL 15 MINUTE) AS ago_15_min
    

    Results

    enter image description here