Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> ORACLE timezone summary

ORACLE timezone summary

From: Martin T. <bilbothebagginsbab5_at_freenet.de>
Date: 26 Sep 2006 09:44:49 -0700
Message-ID: <1159289089.051544.23260@b28g2000cwb.googlegroups.com>


Hi all.
Since I deem all available info and documentation on this matter rather lacking, I have started a short ORACLE+timezone tutorial for myself and my fellow developers.
Fell free to comment on my ramblings.

cheers,
Martin

(sorry, the linebreaks will be f'ed up I fear)



/*

Understanding ORACLE time zone information

*/

--

--

/*
Note: The session timezone hopefully is correctly set by the client environment, but it probably won't hurt to check that your oracle client layer does this correctly on your OS. */

--

--

/*
Note how in the last example the result does *not* contain timezone information. It cannot
since no such information is present in the input data. If the SysTimeStamp is converted to a string with 'TZR TZD' it *still* will only display
the timezone offset as '+/-HH:MM'
*/

SELECT TO_CHAR(

       SysTimeStamp
	   , 'YYYY-MM-DD HH24:MI:SS TZR TZD') from dual;

--

[ Oracle9i Database Reference Release 2 (9.2) ] >>> TZNAME VARCHAR2(64) Time zone region (for example, US/Pacific) >>> TZABBREV VARCHAR2(64) Corresponding daylight abbreviation (for example, PDT) */

CREATE OR REPLACE FUNCTION TIMEZONE_DISPLAY(DATEPART IN VARCHAR2, TZ_MAIN_NAME IN VARCHAR2, TZ_SUMMER_ABBREV IN VARCHAR2) RETURN VARCHAR2
IS

	invalid_timezone EXCEPTION;
	PRAGMA EXCEPTION_INIT (invalid_timezone, -1857);
BEGIN
	RETURN TO_CHAR(
	               TO_TIMESTAMP_TZ(DATEPART||' '||TZ_MAIN_NAME||'
'||TZ_SUMMER_ABBREV, 'YYYY-MM-DD HH24:MI:SS TZR TZD')
				  , 'TZH:TZM');

EXCEPTION
WHEN invalid_timezone THEN

        RETURN NULL;
END; SELECT * FROM (
SELECT tzname TZ_MAIN_NAME, tzabbrev TZ_SUMMER_ABBREV, TO_CHAR(TO_TIMESTAMP_TZ('2006-01-01 12:00:00 '||tzname, 'YYYY-MM-DD HH24:MI:SS TZR'), 'TZH:TZM') AS TZ_OFFSET_REGION_WINTER, TO_CHAR(TO_TIMESTAMP_TZ('2006-07-01 12:00:00 '||tzname, 'YYYY-MM-DD HH24:MI:SS TZR'), 'TZH:TZM') AS TZ_OFFSET_REGION_SUMMER, TIMEZONE_DISPLAY('2006-01-01 12:00:00', tzname, tzabbrev) AS TZ_OFFSET_COMBINED_WINTER,
TIMEZONE_DISPLAY('2006-07-01 12:00:00', tzname, tzabbrev) AS TZ_OFFSET_COMBINED_SUMMER
FROM v$timezone_names )
/* where TZ_OFFSET_COMBINED_WINTER IS NOT NULL

   OR TZ_OFFSET_COMBINED_SUMMER IS NOT NULL */ order by TZ_MAIN_NAME

/*
Note in the SELECT, how some entries TZNAME+TZABBREV in v$timezone_names do not yield a valid time for summer AND winter I really have no clue what this could mean. :)

Note also that some entries in v$timezone_names yield valid offsets (always the same) for summer and winter. */

--

select TO_TIMESTAMP_TZ('2006-07-01 12:00:00 CET CEST', 'YYYY-MM-DD HH24:MI:SS TZR TZD')
from dual; -- OK

select TO_TIMESTAMP_TZ('2006-01-01 12:00:00 CET CEST', 'YYYY-MMM-DD HH24:MI:SS TZR TZD')
from dual; -- ORA-01857!

--

Anyway - as I see it, you *never* need to supply the 'TZR TZD' form when putting data into ORACLE, except if you want to validate that the timezone info on the data is correct.

What you would do in the client is, to ensure the sessiontimezone is set correctly vs. the time zone on the db server and then insert the data accordingly.

Oh, and if you use the <TIMESTAMP WITH TIME *LOCAL* ZONE> datatype you *also* have to ensure that the dbtimezone is set correctly and correctly means that it's the same timezone as the OS the server runs on because otherwise the values will not match!

I'm sure I've forgotten a lot of things, but lets leave it here, shall we? :-)
*/


Received on Tue Sep 26 2006 - 11:44:49 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US