I have a field with a date/time value like this:
2009-11-17 18:40:05
It's in UTC. In the query how can I convert this to EST?
I'm trying something like this but it throws an error.
// datetime is the field name
SELECT
FROM_TZ(TIMESTAMP TO_DATE(datetime, 'yyyy-mm-dd hh24miss'), 'EST') AS DT
FROM
db_name
If you want to convert a date field from UTC to EST, this worked for me:
First, I cast the desired date field (as DATE_FIELD) to a timestamp. The result of the cast is the first parameter of the FROM_TZ function, which requires the parameter to be of type TIMESTAMP. The second parameter is 'UTC', since that is what we are changing from.
Then, I cast the results of that function call back to type DATE and give it an alias.
I had to tweak it slightly to get it to work on my database, but this worked:
The key is the "at time zone" syntax.