17 September 2018 · Asran ·       Add to Favorites   Report

How to cast DATE Column to TIMESTAMP in BigQuery

Solution:

Use the CAST Function CAST(DATE_COLUMN as TIMESTAMP) or just TIMESTAMP(date_column)

#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`   

Result:

Row dt          ts                           ts2
1   2018-06-13  2018-06-13 00:00:00.000 UTC  2018-06-13 00:00:00.000 UTC       

Asran

posted on 17 September 2018

Read great educational content like this and a lot more !

Members get free exclusive access to content, new courses, and discounts. Signup for a free account to write a post / comment / upvote posts. Creating an account takes less than 5 seconds and you can start earning badges & points too

Copied