Solved

convert sysdate into GMT

Posted on 2009-07-15
5
1,755 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 73

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 73

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 73

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now