views:

684

answers:

1

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
+2  A: 

I had to tweak it slightly to get it to work on my database, but this worked:

select from_tz(to_timestamp('2009-11-17 18:40:05','yyyy-mm-dd hh24:mi:ss'), 'UTC') 
at time zone 'America/New_York' from dual

The key is the "at time zone" syntax.

Dan
Thanks I just found that the date was in the wrong format, Duh :)
Phill Pafford
What's that "TIMEZONE TO_DATE(...)" syntax? I've never seen that before.
Dan
Specifying timestamp literals is easier with the ANSI syntax, so you could replace "to_timestamp('2009-11-17 18:40:05','yyyy-mm-dd hh24:mi:ss')" with "timestamp '2009-11-17 18:40:05'" ... a little more compact
David Aldridge