Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bigquery extract epoch from date

I need to extract epoch from the timestamp column in bigquery.
In postgres we can get the epoch using following query:

extract(epoch from timestamp_column)

What is the equivalent in bigquery? How to get epoch from a given date in bigquery?

like image 691
Sandesh Avatar asked May 13 '26 06:05

Sandesh


1 Answers

If you are using Legacy SQL, you can use TIMESTAMP_TO_SEC to convert from timestamp to epoch. So, you can do something like this:

SELECT TIMESTAMP_TO_MSEC(timestamp_column) FROM [YOUR_DATASET:YOUR_TABLE];

If you are using Standard SQL, you can use UNIX_SECONDS for the same purpose.

SELECT UNIX_SECONDS(timestamp_column) FROM `yourdataset.yourtable`; 
like image 145
Mangu Avatar answered May 18 '26 12:05

Mangu