RSS

Informatica Java Transform handling of Dates

29 Jul

I love working with the java transform in informatica because it gives me all the freedom in the world, and it makes my mappings compact, rather than having tens of drag and dropped components. I can usually achieve a lot with only one java transform.

One thing confounded me recently as I could not from in side a java transform assign a date value to an output port I had defined as a date/time port.
So the code below could not work.
date_port_out = New Date();

I tried a bunch of alternatives , example using simpleDateFormat to create a format that is the default in informatica, but nothing was working.
Then I decided to look at the generated code in the java transform

informatica_date_in_java

I couldn’t believe it ; When I create a date/time port, the java transform creates a long out of it. How does it do this, I could guess , but I sure know how to convert a java Date into the millisecond values since epoch (Jan 1st 1970).

long millis_since_epoch = new Date().getTime();

Then I assigned the long value to the output port – and it worked !!

date_port_out = new Date().getTime; 

Also important not to forget to import the Date package in the imports tab;

import java.util.Date;
 
Leave a comment

Posted by on July 29, 2015 in programming, software

 

Tags: , , , ,

Leave a comment