Solved

convert sysdate into GMT

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
query question 13 41
MySQL Select latest stock count records 11 36
sql calculate averages 18 30
How to simplify my SQL statement? 14 21
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
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.
Via a live example, show how to take different types of Oracle backups using RMAN.

762 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

24 Experts available now in Live!

Get 1:1 Help Now