Solved

oracle daylight savings

Posted on 2014-10-22
3
408 Views
Last Modified: 2014-10-22
I am trying to conver the following epoch 1413902247 (2:37 pm on 10/21 in GMT therefre 10:37 am EST) to a date and time. My env is EST and I believe DST is in effect and we are -4 from GMT as of today (10/22/2014).
I have been tring various things below and can get the time. I cannot seem to get it converted to EST with daylight when I use EDT i get invalid timezone?


 SELECT CAST ((from_tz(CAST(to_Date('1970-01-01','YYYY-MM-DD') +1413902247/86400 AS TIMESTAMP),'EST') at TIME ZONE ('US/Eastern')) as DATE) --as EST
,from_tz(cast(to_Date('1970-01-01','YYYY-MM-DD') +1413902247/86400 AS TIMESTAMP),'US/Eastern') as EDT
       ,to_Date('1970-01-01','YYYY-MM-DD') +1413902247/86400 AS TIMESTAMP
--,                          to_char(new_time(to_date('1970-01-01','YYYY-MM-DD HH24:MI:SS') +1413902247/86400000) ,'EST','GMT'),'dd-mon-yyyy hh24:mi:ss') New_TimeGmtTime_DST
   FROM dual
0
Comment
Question by:pcomb
  • 2
3 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 40397449
SELECT (TIMESTAMP '1970-01-01 00:00:00 +00:00' + NUMTODSINTERVAL(1413902247, 'second'))
           AT TIME ZONE 'US/Eastern'
  FROM DUAL


US/Eastern is daylight savings aware, so it will return -04:00 in the DST period  and -05:00 in the Standard period
0
 

Author Comment

by:pcomb
ID: 40397459
perfect thanks
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 40397474
and, if you need to reverse it, then try one of these


SELECT   EXTRACT(DAY FROM i) * 86400
       + EXTRACT(HOUR FROM i) * 3600
       + EXTRACT(MINUTE FROM i) * 60
       + EXTRACT(SECOND FROM i)
  FROM (SELECT TIMESTAMP '2014-10-21 10:37:27 -04:00' - TIMESTAMP '1970-01-01 00:00:00 +00:00' i
          FROM DUAL);

SELECT   EXTRACT(DAY FROM i) * 86400
       + EXTRACT(HOUR FROM i) * 3600
       + EXTRACT(MINUTE FROM i) * 60
       + EXTRACT(SECOND FROM i)
  FROM (SELECT   FROM_TZ(TIMESTAMP '2014-10-21 10:37:27', 'US/Eastern')
               - TIMESTAMP '1970-01-01 00:00:00 +00:00'
                   i
          FROM DUAL);
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question