advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Sidebar 1. About Time Zone Displacement
Sidebar 2. Displaying Time Zone Information
Sidebar 3. Time Zone Names
Sidebar 4. Pitfall: DST and the Oracle Scheduler
Partners & Affiliates
advertisement
advertisement
Average Rating: 5/5 | Rate this item | 5 users have rated this item.
 Print Print
 
Write Time Zone Aware Code in Oracle
Oracle 9i introduced data types and support to handle time zones. Use these data types to make your Oracle code time zone aware. 

advertisement
n our increasingly interconnected world, it's more and more important for code to be able to handle time zones gracefully. For example, if call centers in Bangalore and London use the same call center application, then the code that writes call logs to the database will have to be time zone aware—a call time recorded simply as "7:15 AM" could have happened at 7:15 AM in either London time or in Bangalore time.

Until Oracle 9i, Oracle provided a single data type for dates and times, the DATE data type, and didn't offer any special support for time zones. In Oracle 9i, Oracle provides built-in time zone and Daylight Savings Time support. Instead of trying to stuff time zone functionality into the DATE data type, Oracle introduced TIMESTAMP data types that are time zone aware.

This article explains Oracle's handling of time zones and shows you how to make your code time zone aware.

Introduction to the DATE and TIMESTAMP Data Types

DATEs, the datetime data type from Oracle's earliest releases, store year, month, day, hour, and minute information. DATEs do not store fractional seconds; they offer only seconds-level precision. TIMESTAMPs store all the information DATEs can; they can also store fractional seconds, with a precision of up to 0.00000001 (10^-9) of a second.

You can set the precision of a TIMESTAMP type variable in your code with the following syntax:


TIMESTAMP[(precision)]

The default precision is 6 (i.e., TIMESTAMP(6), which has a precision of 0.000001 (10^-6) seconds).

DATE arithmetic and TIMESTAMP arithmetic have significant differences. If you subtract one date from another, the result is a NUMBER data type specifying the number of days between the two dates. For example, in DATE arithmetic, to_date('1/12/2005 13:00') - to_date('1/12/05 12:00') = 0.041666..., or 1/24 of a day. But in TIMESTAMP arithmetic, the interval between two timestamps is expressed in a new INTERVAL data type. INTERVALS display the year, month, day, hour, minute, second, and fractional-seconds difference between two timestamps. Performing the calculation above on TIMESTAMPs instead of DATEs would give you an INTERVAL of +000000000 01:00:00.000000 instead of .041666. This much more clearly indicates that there is one hour's difference between the two TIMESTAMPs.

Finally, Oracle provides special TIMESTAMP data types that, unlike DATEs, offer time zone support. From 9i on, Oracle has provided time zone support within the database, and you can write your code so that it's time zone aware by using these special TIMESTAMP data types. The following are the four datetime data types in Oracle:

  • DATE
  • TIMESTAMP
  • TIMESTAMP WITH TIME ZONE
  • TIMESTAMP WITH LOCAL TIME ZONE

The TIMESTAMP WITH TIME ZONE data types and TIMESTAMP WITH LOCAL TIME ZONE data types are time zone aware (See Sidebar 1. About Time Zone Displacement). Use these data types in your code to take advantage of Oracle's time zone and daylight savings time functionality.

Page 1 of 4
advertisement
  Next Page: The Two Time-Zoned Data Types
Page 1: IntroductionPage 3: Putting It Together
Page 2: The Two Time-Zoned Data TypesPage 4: Setting Up the Right Time Zone
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES