Search code examples
sqlgoogle-bigquerytimestampunix-timestamp

Using standart sql, how to convert timestamp to unix time?


In mysql, one can do this in order to compare 2 timestamp :

where UNIX_TIMESTAMP(transaction.closed_on)<UNIX_TIMESTAMP(transaction.opened_on)...

What’s the equivalent function for Google bigquery ?


Solution

  • ... to subtract 2 timestamp : ...

    you can use TIMESTAMP_DIFF(closed_on, opened_on, SECOND) for BigQuery Standard SQL

    to compare in WHERE clause

    WHERE closed_on < opened_on

    finally, to convert timestamp to unix time ...

    Use UNIX_SECONDS() function