Showing posts with label Timestamp Conversion. Show all posts
Showing posts with label Timestamp Conversion. Show all posts

(WMB) Timestamp Conversion

Often we require to change time stamp from one format to another.
Below esql code shows how to convert an incoming data (which is a time stamp in string) into time stamp or String of the desired format.


Declare srcFormat CHARACTER; -- Source (Incoming time stamp format)
Declare targetFormat CHARACTER; -- Target (Expected time stamp format)
DECLARE InTime TIMESTAMP; 
SET srcFormat = 'yyyy-MM-dd HH:mm:ss.SSS';
SET targetFormat = 'yyyy-MM-dd''T''HH:mm:ss.SSS';


-- Converting string into time stamp of same format.
SET InTime  =  cast(InputBody.time as TIMESTAMP FORMAT srcFormat);


-- Converting time stamp to string of target format.
SET OutputRoot.XMLNSC.out.time = cast(InTime as CHARACTER FORMAT targetFormat);