Comparing numeric dates using iSeries query

Many legacy systems stores dates in 6 digit numeric fields. This makes comparison difficult during a Query’s select statements. However, there is a way to handel these dates in Query/400.  Firstly, convert the numeric date field to a character field and formatting it with separators. Then it can be converted to a date field using the DATE function in query.

Example:

 

                Define Result Fields

Field       Expression     
DMYCHAR     substr(digits(dmydat1),1,2)!!'/'!! 
            substr(digits(dmydat1),3,2)!!'/'!! 
            substr(digits(dmydat1),5,2)        

DMYCHAR2    substr(digits(dmydat2),1,2)!!'/'!! 
            substr(digits(dmydat2),3,2)!!'/'!! 
            substr(digits(dmydat2),5,2) 
                                             
DMYDATE     date(dmychar)   

DMYDATE2    date(dmychar2)



                     Select Records                              
                                                                                                                                      
 AND/OR  Field             Test   Value  
         DMYDATE           GT     DMYDATE2                                   
                     

Posted in tips.