问题
Hi I have a date field (Open_Time) containing timestamp data. The times in this column are in UTC. I want to select that column and convert it to EST and insert it into another table. I want it to be EST for the time at the original timestamp (take into account daylight savings time based on what day month and year it was). I have been reading about the various timezone functions in oracle but most seem to focus on altering the database's timezone which I don't need to do. The (Open_Time) field is always recorded in UTC.
BLUF: I need to select a time_stamp field (Open_Time) that was recorded according to UTC time and convert it to what EST was at the time of (Open_Time). Thanks.
回答1:
If you are using the TIMESTAMP WITH TIME ZONE data type:
Oracle Setup:
CREATE TABLE Table_Name (
open_time TIMESTAMP WITH TIME ZONE
);
INSERT INTO Table_Name VALUES ( SYSTIMESTAMP AT TIME ZONE 'UTC' );
Query:
SELECT open_time AT TIME ZONE 'UTC' AS utc,
open_time AT TIME ZONE 'EST' AS est
FROM Table_Name;
Output:
UTC EST
----------------------------------- -----------------------------------
02-MAR-16 22.41.38.344809000 UTC 02-MAR-16 17.41.38.344809000 EST
or if you are just using the TIMESTAMP data type:
Oracle Setup:
CREATE TABLE Table_Name (
open_time TIMESTAMP
);
INSERT INTO Table_Name VALUES ( SYSTIMESTAMP );
Query:
SELECT CAST( open_time AS TIMESTAMP WITH TIME ZONE ) AT TIME ZONE 'UTC' AS utc,
CAST( open_time AS TIMESTAMP WITH TIME ZONE ) AT TIME ZONE 'EST' AS est
FROM Table_Name;
Output:
UTC EST
----------------------------------- -----------------------------------
02-MAR-16 22.41.38.344809000 UTC 02-MAR-16 17.41.38.344809000 EST
来源:https://stackoverflow.com/questions/35759390/how-do-i-convert-an-oracle-timestamp-value-from-utc-to-est-in-a-select-statement