Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert timestamp to seconds in BigQuery Standard SQL

In BigQuery Legacy Sql, we use timestamp_to_sec() function to convert timestamp to seconds. What is its equivalent in BigQuery Standard SQL?

like image 404
abhishek jha Avatar asked Aug 14 '16 20:08

abhishek jha


People also ask

What is timestamp format in BigQuery?

DATETIME. TIMESTAMP. The date in the format %Y-%m-%d. 2021-01-20.

What is the difference between datetime and timestamp in BigQuery?

Datetime type: comprises both calendar date and time. It does not store time zone information: YYYY-MM-DD HH:MM:SS (e.g. ). Timestamp type: comprises date, time, and time zone information.

How do I convert a timestamp to a date in SQL?

To record a date or time, use a datetime2 data type. So you cannot convert a SQL Server TIMESTAMP to a date/time - it's just not a date/time. But if you're saying timestamp but really you mean a DATETIME column - then you can use any of those valid date formats described in the CAST and CONVERT topic in the MSDN help.


1 Answers

BigQuery Legacy SQL

SELECT TIMESTAMP_TO_SEC(CURRENT_TIMESTAMP()) 

BigQuery Standard SQL

SELECT UNIX_SECONDS(CURRENT_TIMESTAMP())
like image 164
Mikhail Berlyant Avatar answered Oct 12 '22 19:10

Mikhail Berlyant