Home » SQL & PL/SQL » SQL & PL/SQL » SYSDATE Central to Eastern time (Oracle 11gR2 11.2.0.4)
SYSDATE Central to Eastern time [message #616781] Fri, 20 June 2014 11:47 Go to next message
kvignes1
Messages: 33
Registered: September 2007
Member

Environment : Oracle Data Appliance ( Oracle 11g R2 11.2.0.4)
RAC 2-node.
OS is running in Central Timezone.

We are in process of migrating database from standalone Server database in different timezone to ODA - Central Timezone. But we would like to retain the different timezone in each database in ODA as well.

In all these databases, applications are using SYSDATE to insert the records into the tables. what I read, sysdate comes from OS date which in this case is central timezone. But I would like to have the eastern timezone database to display date and time in Eastern eventhough OS is in Central.

To test this scenario, we took some existing database which is in central timezone and tried to change it to Eastern using below commands. When i query the sysdate it still shows in Central time not in eastern time.

If we need to get Eastern time sysdate, is the only option is when we create the database to mention it? using (SET TIME_ZONE='')? or any init parameter ?

How do i get the sysdate in Eastern instead of central?

Quote:


SQL> ALTER DATABASE SET TIME_ZONE='US/Eastern';

Database altered.

SQL> ALTER DATABASE SET TIME_ZONE='-04:00';

Database altered.

SQL>


############################################################################
oracle@ /home/oracle $ srvctl stop database -d EPD
oracle@ /home/oracle $
oracle@ /home/oracle $
oracle@ /home/oracle $ srvctl start database -d EPD
oracle@ /home/oracle $
############################################################################



SQL> -- Current date/time, in Database TZ
SQL> SELECT SYSTIMESTAMP FROM DUAL;

SYSTIMESTAMP
---------------------------------------------------------------------------
20-JUN-14 10.54.40.736969 AM -05:00

SQL>
SQL> --Current date/time, in Client Session TZ
SQL> SELECT CURRENT_TIMESTAMP FROM DUAL;

CURRENT_TIMESTAMP
---------------------------------------------------------------------------
20-JUN-14 10.54.40.766976 AM -05:00

SQL>
SQL> --Local date/time in Client Session, but with no TZ info
SQL> SELECt LOCALTIMESTAMP FROM DUAL;

LOCALTIMESTAMP
---------------------------------------------------------------------------
20-JUN-14 10.54.40.796888 AM

SQL>
SQL> --Database time zone, in HH:MI offset from GMT
SQL> SELECT DBTIMEZONE FROM DUAL;

DBTIME
------
-04:00

SQL>
SQL> --Session time zone, in HH:MI offset from GMT
SQL> SELECT SESSIONTIMEZONE FROM DUAL;

SESSIONTIMEZONE
---------------------------------------------------------------------------
-05:00

SQL>
SQL> SELECT TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS') FROM DUAL;

TO_CHAR(SYSDATE,'DD-
--------------------
20-JUN-2014 10:54:41









Re: SYSDATE Central to Eastern time [message #616784 is a reply to message #616781] Fri, 20 June 2014 11:56 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
One more question about date display. The order of precendence comes into play and has its own importance. And when you have an application/multiple databases it is really tricky. Have a look at http://edstevensdba.wordpress.com/2011/04/07/nls_date_format/. It will give you some idea. Come back if you have additional questions.
Re: SYSDATE Central to Eastern time [message #616786 is a reply to message #616784] Fri, 20 June 2014 12:08 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
SYSDATE contains nothing about any timezone.
so nothing you do involving TIMEZONE has any impact on any DATE column populated by SYSDATE.
It is like today you paint your front door different color, & you expect a picture of this same door taken yesterday to show the new color.
Re: SYSDATE Central to Eastern time [message #616788 is a reply to message #616784] Fri, 20 June 2014 12:12 Go to previous messageGo to next message
kvignes1
Messages: 33
Registered: September 2007
Member

Thanks Lalit.

Gone through the article and it talks abt date and its format conversion. Nothing abt Timezone conversion.

My Question is:
My OS is in Central.
How to change SYSDATE time from Central to Eastern after the database creation. Tried ALTER DATABASE SET TIME_ZONE but didnt change the SYSDATE , it changed DBTIMEZONE alone.

Only option is to recreate the database with SET TIME_ZONE parameter?
Re: SYSDATE Central to Eastern time [message #616789 is a reply to message #616781] Fri, 20 June 2014 12:14 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
Another point to take into account
http://docs.oracle.com/cd/E16655_01/server.121/e17209/statements_1006.htm#SQLRF52554
Quote:

...
Oracle Database normalizes all new TIMESTAMP WITH LOCAL TIME ZONE data to the time zone of the database when the data is stored on disk.Oracle Database does not automatically update existing data in the database to the new time zone. Therefore, you cannot reset the database time zone if there is any TIMESTAMP WITH LOCAL TIME ZONE data in the database. You must first delete or export the TIMESTAMP WITH LOCAL TIME ZONE data and then reset the database time zone. For this reason, Oracle does not encourage you to change the time zone of a database that contains data.
...
Re: SYSDATE Central to Eastern time [message #616790 is a reply to message #616788] Fri, 20 June 2014 12:16 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Stop, think about SYSDATE and TIMEZONE. Why do you think they are synonymous as per your explanation.
Re: SYSDATE Central to Eastern time [message #616792 is a reply to message #616788] Fri, 20 June 2014 12:16 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
kvignes1 wrote on Fri, 20 June 2014 19:12

How to change SYSDATE time from Central to Eastern after the database creation. Tried ALTER DATABASE SET TIME_ZONE but didnt change the SYSDATE , it changed DBTIMEZONE alone.


http://docs.oracle.com/cd/E16655_01/server.121/e17209/functions201.htm#SQLRF06124
Quote:
SYSDATE returns the current date and time set for the operating system on which the database server resides.

Re: SYSDATE Central to Eastern time [message #616793 is a reply to message #616789] Fri, 20 June 2014 12:17 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>How to change SYSDATE time from Central to Eastern after the database creation.
SYSDATE contains NO timezone component; so there is NOTHING to change!
SYSDATE contains NO timezone component; so there is NOTHING to change!
SYSDATE contains NO timezone component; so there is NOTHING to change!
DB TIMEZONE has ZERO impact on SYSDATE value
Re: SYSDATE Central to Eastern time [message #616796 is a reply to message #616786] Fri, 20 June 2014 12:22 Go to previous messageGo to next message
kvignes1
Messages: 33
Registered: September 2007
Member

Thanks.

I need some advice.
Operating System is in Central TZ. My existing database shows SYSDATE in Central time. How do i change the SYSDATE "Time" to Eastern without any application change? Will dropping and recreating the DB (with SET TIME_ZONE = '+04:00') help?


Re: SYSDATE Central to Eastern time [message #616797 is a reply to message #616796] Fri, 20 June 2014 12:24 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>How do i change the SYSDATE "Time" to Eastern without any application change?
set OS SERVER time to report Eastern Timezone is the ONLY way to have SYSDATE produce what you desire
Re: SYSDATE Central to Eastern time [message #616798 is a reply to message #616797] Fri, 20 June 2014 12:26 Go to previous messageGo to next message
kvignes1
Messages: 33
Registered: September 2007
Member

Thank You Sir.
Re: SYSDATE Central to Eastern time [message #616812 is a reply to message #616796] Fri, 20 June 2014 14:31 Go to previous message
EdStevens
Messages: 1377
Registered: September 2013
Senior Member
kvignes1 wrote on Fri, 20 June 2014 12:22
Thanks.

I need some advice.
Operating System is in Central TZ. My existing database shows SYSDATE in Central time.


No, your database does NOT show SYSDATE in Central time.
One more time, slowly and with emphasis: SYSDATE does NOT carry ANY information about timezone. It simply reports the time from the clock on the host operating system where the database is running. Now, if it so happens that that time is set for Central Time, so be it. It is what it is. No different than that analog clock hanging on the wall. Does it say anything about any time zone? No, it does not. It just show "a" time. Same as the system clock on your server, which is where SYSDATE gets its information.

Quote:
How do i change the SYSDATE "Time" to Eastern without any application change? Will dropping and recreating the DB (with SET TIME_ZONE = '+04:00') help?

No, because, once again, sysdate has no information about time zone. If your application cares about time zones, then your application needs to store dates and times in a data type that carries information about time zones.




Previous Topic: Multibyte character
Next Topic: doubt regarding exception handling?
Goto Forum:
  


Current Time: Mon Aug 11 01:37:56 CDT 2025