CSS

Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts

Wednesday, March 26, 2014

Java Epoch to TIMESTAMP function

One of the timestamps in one tables I work with is stored as a java epoch.  Here is a function I wrote to convert it to a timestamp.

This is done in DB2 on a iSeries so some you may need to edit it some.  In particular ant line that *SomeWord is probably a iSeries thing.

CREATE FUNCTION YFUALFA.TIMESTAMP_EPOCH ( 
 EPOCH BIGINT ) 
 RETURNS TIMESTAMP   
 LANGUAGE SQL 
 SPECIFIC YFUALFA.TIMESTAMP_EPOCH 
 DETERMINISTIC 
 READS SQL DATA 
 RETURNS NULL ON NULL INPUT 
 NO EXTERNAL ACTION 
 SET OPTION  ALWBLK = *ALLREAD , 
 ALWCPYDTA = *OPTIMIZE , 
 COMMIT = *NONE , 
 DECRESULT = (31, 31, 00) , 
 DFTRDBCOL = *NONE , 
 DYNDFTCOL = *NO , 
 DYNUSRPRF = *USER , 
 SRTSEQ = *HEX   
 RETURN TIMESTAMP ( '1970-01-01' , '00:00:00' ) + EPOCH SECONDS  ; 
  
COMMENT ON SPECIFIC FUNCTION YFUALFA.TIMESTAMP_EPOCH 
 IS 'Timestamp from a Java epoch' ;