title: Convert CHAR to TIMESTAMP in DB2 iSeries
body: <p>I've googling about how to convert CHAR into TIMESTAMP in DB2 iSeries with no luck, can u help me ?</p>
  
  <p>Eg: 20120216  </p>
  
  <p>Expected Result : 16/2/2012 12:00:00 AM </p>
  
  <p>MY UDF :</p>
  
  <pre><code>CREATE FUNCTION TEST.CONVERT_TO_TIMESTAMP (VAL CHARACTER VARYING(20))
  RETURNS TIMESTAMP
  LANGUAGE SQL
  SPECIFIC TEST.CONVERT_TO_TIMESTAMP
  MODIFIES SQL DATA
  CALLED ON NULL INPUT
  FENCED
  DISALLOW PARALLEL
  NO EXTERNAL ACTION
  BEGIN ATOMIC
  DECLARE SQLCODE INTEGER DEFAULT 0 ;
  DECLARE RETCODE INTEGER DEFAULT 0 ;
  DECLARE RET TIMESTAMP ;
  DECLARE CONTINUE HANDLER FOR SQLEXCEPTION , SQLWARNING , NOT FOUND
  BEGIN
  SET RETCODE = SQLCODE ;
  END ;
  
  IF ( VAL IS NOT NULL ) THEN
  SET RET = CAST ( VAL AS TIMESTAMP ) ;
   ELSE
  SET RET = NULL ;
    END IF ;
  
   RETURN RET ;
  
   END 
   GO
  </code></pre>
  
  <p>--</p>
  
  <p>And the result is null :(</p>
  
  <p>Any Suggestion ?</p>
  
  <p>Thanks
  MRizq</p>