Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

BigQuery – Convert Datetime to local timezone?

I have a DateTime column with data like "2020-08-05T10:19:30" in UTC.

I need to convert this to either "America/Los Angeles" or "America/Chicago" timezone with a BigQuery SQL call.

I’ve tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT A, B, C, DATETIME(date_field,"America/Los Angeles") as new_date_field FROM table;

I get this:

"No matching signature for function DATETIME for argument types:
DATETIME, STRING. Supported signatures: DATETIME(INT64, INT64, INT64,
INT64, INT64, INT64); DATETIME(DATE, TIME); DATETIME(TIMESTAMP,
[STRING]); DATETIME(DATE); DATETIME(DATETIME); DATETIME(STRING)"

>Solution :

Try below

SELECT A, B, C, 
  DATETIME(timestamp(date_field),"America/Chicago") as new_date_field 
FROM table;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading