I am querying a table on BigQuery that has a field in the 'DATE' format. I want to read this in the 'TIMESTAMP' format. I tried converting the DATE to an integer and then converting into a TIMESTAMP but doesn't seem to work.
The format is: YYYY-MM-DD HH:MM:SS (e.g. 2021-05-15 16:45:23). Timestamp type: Date, time, and time zone information are all included in timestamps. If no time zone is given, the format falls back to UTC. The format is: YYYY-MM-DD [Timezone] HH:MM:SS (e.g. 2021-05-15 16:45:18 UTC).
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.
#standardSQL
WITH `project.dataset.table` AS (
SELECT CURRENT_DATE() AS dt
)
SELECT dt, CAST(dt AS TIMESTAMP) AS ts,
TIMESTAMP(dt) AS ts2
FROM `project.dataset.table`
with result as
Row dt ts ts2
1 2018-06-13 2018-06-13 00:00:00.000 UTC 2018-06-13 00:00:00.000 UTC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With