The following sample ILE RPG code formats the ISO date/time field so that it can be inserted into a SQL Server datetime or smalldatetime field. 
 
This example converts an ISO date field named DATE1 into the following string format, where the hours are in 24-hour time:
 
MM/DD/YYYY  HH:MM:SS
 

Sample Code

D DateMDY         S             20A     
D TimeHMS         S             20A     
D DateTime        S             40A     
*--------------------------------------------------------------------- 
*                  ** Convert date from ISO timestamp to MM/DD/YYYY    
*--------------------------------------------------------------------- 
C                   EXTRCT    DATE1:*M      MM                2         
C                   EXTRCT    DATE1:*D      DD                2         
C                   EXTRCT    DATE1:*Y      YYYY              4         
C                   Eval      DateMDY = %trim(MM) + '/' +               
C                                      %trim(DD) + '/' +                
C                                      %trim(YYYY) 
*--------------------------------------------------------------------- 
*                  ** Convert time from ISO timestamp to HH:MM:SS
*--------------------------------------------------------------------- 
C                   EXTRCT    DATE1:*H      HH                2         
C                   EXTRCT    DATE1:*M      MM                2         
C                   EXTRCT    DATE1:*S      SS                2         
C                   Eval      TimeHMS = %trim(HH) + ':' +               
C                                      %trim(MM) + ':' +                
C                                      %trim(SS)                      
*--------------------------------------------------------------------- 
*                  ** Build date format string as MM/DD/YYYY HH:MM:SS
*--------------------------------------------------------------------- 
C                   Eval      DateTime = %trim(DateMDY) + ' ' + 
C                                        %trim(TIMEHMS)

 


Still have questions? We can help. Submit a case to Technical Support.

Last Modified On: December 10, 2016