fhg
Volume 7, Number 1 -- January 10, 2007

Exporting DB2/400 Dates to Excel

Published: January 10, 2007

by Jeff Haddix

In order for Microsoft's Excel spreadsheet to recognize the set of values for a column as dates, those values must be stored as a number of days. For example, to export the date December 26, 2006, to an Excel spreadsheet, you should export the number 37,066, not a date value like 12/26/2006 or 2006-12-26. However, due to an acknowledged defect in Excel, be aware of the following.

Even though Excel claims that 01/01/1900 equates to Day 1, for most purposes it is necessary to actually use 12/31/1899 as Day 1. Otherwise, a one-day discrepancy will occur when converting IBM DB2 dates (where Day 1 is 01/01/0001) after 02/28/1900 into Excel.

The reason is that Excel does not accurately apply the leap year calculation, while IBM does. The frequently ignored part of the calculation is that century years (1700, 1800, 1900, and so forth) are not leap years, even though they are multiples of four. The exception to that rule is that every 400 years (1200, 1600, 2000, etc.) the century year is a leap year.

As such, February 1900 only had 28 days. However Excel erroneously includes a 29th day, thus creating a one-day offset for all subsequent date conversions.

In the simple test below, a short series of integers was keyed and then those cells were formatted as dates. Notice that Excel improperly converts day 60 to 2/29/1900, which is a non-existent date, thus creating a one-day offset for all subsequent integer date conversions.



The following SQL query demonstrates how to derive Excel compatible dates from columns defined as either legacy packed-decimal date values or with a DATE datatype.

select   DECIMAL_DATE,                                           
           days( date( substr(digits(DECIMAL_DATE),1,4) || '-' ||
                       substr(digits(DECIMAL_DATE),5,2) || '-' ||
                       substr(digits(DECIMAL_DATE),7,4) ) )      
         - days( date('1899-12-30') )  as DAYS_FROM_DECIMAL_DATE,
         ISO_DATE,                                               
           days( ISO_DATE)                                       
         - days( date('1899-12-30') )  as DAYS_FROM_ISO_DATE     
from     DATETABLE 
order by 1 desc

This will return a result set similar to the following.

DECIMAL_DATE  DAYS_FROM_DECIMAL_DATE  ISO_DATE    DAYS_FROM_ISO_DATE
 2006/12/26              39,077       2006-12-26            39,077  
 2006/12/17              39,068       2006-12-17            39,068  
 2006/12/01              39,052       2006-12-01            39,052  
 2006/02/01              38,749       2006-02-01            38,749  
 2006/01/01              38,718       2006-01-01            38,718  
 2003/05/11              37,752       2003-05-11            37,752  
 2003/05/01              37,742       2003-05-01            37,742  
 2003/04/22              37,733       2003-04-22            37,733  
 2003/04/15              37,726       2003-04-15            37,726  
 2003/04/01              37,712       2003-04-01            37,712  
 2003/03/01              37,681       2003-03-01            37,681  
 2003/02/08              37,660       2003-02-08            37,660  
 2003/01/15              37,636       2003-01-15            37,636  
 2003/01/06              37,627       2003-01-06            37,627  
 2003/01/02              37,623       2003-01-02            37,623  
 2003/01/01              37,622       2003-01-01            37,622  
 2002/12/15              37,605       2002-12-15            37,605  
 2002/12/10              37,600       2002-12-10            37,600  

Happy date data exporting, everyone.

Jeff Haddix is the software architect at Alliance Data, which provides application software for utility companies. He can be reached at jeff_haddix@yahoo.com.



                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
PRODATA COMPUTER SERVICES

Join the DBU-on-Demand Club!
As a member of the DBU-on-Demand Club, you can use DBU-on-Demand FREE for up to 5 days anytime and anywhere! Your account will have a credit of $50 US dollars. You can activate DBU and your account will automatically be deducted $10 for a day's usage.

You can replenish this amount at anytime by calling 800.228.6318 or through the client portal.

Join the elite DBU-on-Demand Club!

ProData Computer Services
800.228.6318
www.DoDBU.com


Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

COMMON:  Join us at the Annual 2007 Conference & Expo, April 29 - May 3, in Anaheim, California
Bytware:  StandGuard Network Security 3.0, the next generation of System i security
Asymex:  Control spool files automatically with SpooliT - intelligent iSeries spool file management


The Four Hundred
IBM's System i Priorities for 2007

Arrow Buys Agilysys' IT Distribution Business for $485 Million

Uncle Sam Pushes Energy Star Ratings for Servers

As I See It: Questioning Retirement

The Linux Beacon
Red Hat Unaffected By Oracle Unbreakable Linux in Fiscal Q3

OpenVZ Project Supports Virtualized Linux on Sun's Sparc T1 Chips

The IT Analysts Make Their 2007 Predictions

Arrow Buys Agilysys' IT Distribution Business for $485 Million

Four Hundred Stuff
Magic Adapts iBOLT for J.D. Edwards

Original Adds Some Manual Features to Testing Suite

Bug Busters Debuts Record-Level Mirroring Solution

GeneXus to Bring Major Changes to IDE with 'Rocha'

Big Iron
The IT Analysts Make Their 2007 Predictions

Top Mainframe Stories and Vendor Announcements

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
January 6, 2007: Volume 9, Number 1

December 30, 2006: Volume 8, Number 50

December 23, 2006: Volume 8, Number 49

December 16, 2006: Volume 8, Number 48

December 9, 2006: Volume 8, Number 47

December 2, 2006: Volume 8, Number 46

The Windows Observer
Microsoft Patches Two Zero-Day Exploits, Leaves Two Untouched

Vista Will Boost IT Industry Revenues, Computer Costs

Microsoft's New 'Voice Server' Enters Beta

The Top 10 Warning Signs You May Need a PSA Solution

The Unix Guardian
Latest Dispatch from the Unix Server Wars

Forrester Predicts IT Spending Slowdown in 2007

Evans Data Cases Programming Language Popularity

The X Factor: You Can't Steal What's Free, But You Can Pay a Lot for Something That Isn't Worth It

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

ProData Computer Services
SEQUEL
CYBRA



TABLE OF CONTENTS
Exporting DB2/400 Dates to Excel

Resetting Your QSECOFR Service Tools Password

Admin Alert: Combating Cross-Server Failures for the i5 Manager

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
How much space is taken up on disk by variable-length field?

Multi member source file--need to process all members

SFLINZ and SFLFOLD

Copy spoolfiles from one AS/400 to another

Embedded SQL intermittently causing problems





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement