Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Article -> Convertion of Time Zones in Oracle

This is a discussion on Article -> Convertion of Time Zones in Oracle within the Oracle forums, part of the Databases category; Hi All, Find below some useful information about Time Zone Conversion in oracle. Hope this would be helpful for many of them since all the real time projects that we ...

Go Back   Geeks Talk > Databases > Oracle
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

Oracle Oracle 9i & Oracle 10g Knowledge Base Learn and Share Oracle Technology related articles, white papers, tutorials / study materials, example codes, FAQ's, Tips and Tricks.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-17-2008
Expert Member
 
Join Date: Nov 2008
Location: Chennai
Posts: 303
Thanks: 1
Thanked 37 Times in 32 Posts
amitpatel66 is on a distinguished road
Exclamation Article -> Convertion of Time Zones in Oracle

Hi All,

Find below some useful information about Time Zone Conversion in oracle. Hope this would be helpful for many of them since all the real time projects that we work in follow different time zones (EST,PST etc) and you might well need to convert them to something specific as per your requirements:

insert into dates values(6, to_date('09/20/05 23:15', 'MM/DD/YY HH24:MI'));

The contents of the table now look like this:

1 09/14/05, 21:08
2 09/27/05, 00:00
3 10/02/05, 22:05
4 09/01/05, 17:01
5 09/12/05, 14:30
6 09/20/05, 23:15

Changing Time Zones

The date format in Oracle does not contain time zone information, but the database does. To find out the time zone set, execute this query:

SELECT dbtimezone FROM dual;

DBTIME
——
-04:00


The time zone can be updated with the command:

ALTER database SET TIME_ZONE = '-05:00';

where you can specify the offset from Greenwich mean time or a valid time zone from the list in the v$timezone_names view. Note that this is one of the few of the ‘v$’ views which are plural.

Switching Time Zones

The function new_time is used to convert a time to different time zones. To illustrate this we’ll look at entry 5 from the dates file.

SELECT entry, to_char(entry_date, 'MM/DD/YY HH:MI AM') FROM dates WHERE entry=5;

5 09/12/05 02:30 PM

This database is in US Eastern time but we want to display the time in US Central.

SELECT entry, to_char(new_time(entry_date, 'EST', 'CST'), 'MM/DD/YY HH:MI AM') FROM dates WHERE entry=5;
5 09/12/05 01:30 PM


Here we clearly see the time converted to Central. Note that the new_time function is performed on the date field, not on the to_char.

Now let’s grab this time in Pacific time:

SELECT entry, to_char(new_time(entry_date, 'EST', 'PST'), 'MM/DD/YY HH:MI AM') FROM dates WHERE entry=5;
5 09/12/05 11:30 AM


Now we see not only the time converted, but also the time of day has gone from PM to AM.

Now let’s take a look at entry 6:

SELECT entry, to_char(entry_date, 'MM/DD/YY HH:MI AM') FROM dates WHERE entry=6;

6 09/20/05 11:15 PM


We’ll again assume this timestamp is in US Eastern time, but let’s convert it this time to Greenwich Mean Time.

SELECT entry, to_char(new_time(entry_date, 'EST', 'GMT'), 'MM/DD/YY HH:MI AM') FROM dates WHERE entry=6;
6 09/21/05 04:15 AM


This shows not only the change in hours, but that the date of this entry is displayed properly for its time zone. Of course the new_time function can be used on inserts in the same way. This is useful if you are allowing input from people in different geographical regions.

Here we convert an entry made in Pacific Time to Eastern:

Code:
INSERT INTO dates
VALUES (7,
new_time(to_date(’09/22/05 10:28 AM’, ‘MM/DD/YY HH:MI AM’), ‘PST’, ‘EST’));
SELECT entry, to_char(entry_date, ‘MM/DD/YY HH:MI AM’) FROM dates WHERE entry=7;
7 09/22/05 01:28 PM
So we have converted 10:28 AM Pacific to 1:28 PM Eastern so all our entries in the table are consistent. Of course when performing the insert we need to put the to_date function within the new_time function so the text string is converted to a date format before we try to convert it.

Last edited by amitpatel66; 11-17-2008 at 10:57 AM. Reason: Spellings
Reply With Quote
The Following 3 Users Say Thank You to amitpatel66 For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 07-06-2009
Junior Member
 
Join Date: Jul 2009
Location: Bangalore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Infinityusers is on a distinguished road
Re: Article -> Convertion of Time Zones in Oracle

Hey Buddy,

Thanks for the notes...
Really very helpful
Reply With Quote
Reply

  Geeks Talk > Databases > Oracle

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Oracle Forms first time use prem_18 Oracle 0 08-14-2008 03:18 PM
Non-global zones Ucy79 Unix/Linux 0 08-07-2008 11:00 PM
Note the Time taken by a query using Loadrunner with Oracle NCA protocol LA TSTENG LoadRunner 2 02-13-2008 07:21 AM
Excel Convertion krishnaindia2007 Oracle 6 12-03-2007 01:31 AM


All times are GMT -4. The time now is 02:24 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved