Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bigquery - select timestamp as human readable datetime

How to select timestamp(stored as seconds) as human readable datetime in Google Bigquery?

schema

id(STRING) | signup_date(TIMESTAMP)

I wrote a query using DATE function, but getting error

SELECT DATE(create_date) FROM [accounts] 

Error: Invalid function name: DATE; did you mean CASE?

Thanks!

like image 543
tning Avatar asked Jun 03 '15 08:06

tning


People also ask

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 change timestamp to date?

You can simply use the fromtimestamp function from the DateTime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the corresponding DateTime object to timestamp.


1 Answers

I think I found a working solution from Bigquery reference page. Basically BigQuery stores TIMESTAMP data internally as a UNIX timestamp with microsecond precision.

SELECT SEC_TO_TIMESTAMP(date) FROM ...
like image 96
tning Avatar answered Sep 28 '22 10:09

tning