Search code examples
sqlssisibm-midrangey2k

How Do I Convert a Y2K Date to SQL DATE In SSIS?


I am using SSIS (SQL 2008) to bring data over from an AS400. The date values are stored in the 400 as a 7 digit numeric. Here is the format: "CYYMMDD" C is a "century digit" where 0 = 1900 and 1 = 2000. I have been looking into derived columns and script components. I am very new to SSIS and all the casting required compounded with different cases is making me a dull boy. Also, I am losing leading zeros. I am not sure if that is b/c they are numeric type and I would see them correctly if I cast as string or not. Below is what I am seeing in SQL after a direct pull from the 400 using SSIS.

AS400   =   Actual 
101         01/01/1900 (I think these are "unknown" dates)
1231        12/31/1900 (I think these are "unknown" dates)
20702       07/02/1902
151231      12/31/1915
1000102     01/02/2000
1110201     02/01/2011

Solution

  • Neither of the two answers were 100%, but both helped me to figure out the prob. Not sure whom to mark as "correct" Here is what I did. Had to do 2 derived columns.

    1. ((DT_WSTR,8)(<<AS400>> + 19000000)) 
    2. (DT_DBDATE)(SUBSTRING(DCDateString,1,4) + "-" + SUBSTRING(DCDateString,5,2) + "-" + SUBSTRING(DCDateString,7,2))