Solved

convert sysdate into GMT

Posted on 2009-07-15
5
1,799 Views
Last Modified: 2013-12-19
How do we convert the sysdate to GMT format.
select dbtimezone does give us the GMT offset and not the literal 'time zone'
This makes using 'to_char(new_time(entry_date, 'EST', 'CST')' kind of approach impossible - as it does not accept offsets.

How then do we get the 'TZ' of the database - alternatively how do we convert the sysdate into GMT.
0
Comment
Question by:ranadhir
  • 3
5 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 24861528
I recommend NOT using dbtimezone.

Oracle recommends it only ever be set to +0:00
if you want times with timezones

use systimestamp instead of sysdate


0
 
LVL 74

Accepted Solution

by:
sdstuber earned 75 total points
ID: 24861576
try this....

SELECT
       SYSTIMESTAMP,
       SYSDATE local_sysdate,
       SYSDATE - EXTRACT(TIMEZONE_HOUR FROM SYSTIMESTAMP) / 24 gmt_sysdate
FROM   DUAL
0
 

Author Comment

by:ranadhir
ID: 24866541
this works great - thanks
 just one question since you advised against dbtimezone.

Given a time zone region is it fine to V$TIMEZONE_NAMES in my PL/SQL to get teh corresponding TZ abbrev.
Also,given a off-set is there a way to get the corresponding TZ?
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 24866584
There is no reliable way to go from an offset to an abbreviation using ONLY the offset as your input information
because an offset can have multiple meanings from observation of Daylight Saving Time and/or regional abbreviations.

EST and CDT have the same offset (-5)   (Easter Standard vs Centeral Daylight)  - daylight observation
EDT and ECT have the same offset (-4)  (Eastern Daylight vs Eastern Caribbean) - daylight observation and region

You can build your own lookup table of abbreviations and offsets that map 1-to-1.
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to recover a database from a user managed backup
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

726 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