Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
rp2018
Creator
Creator

How to convert date format to integer?

Have a source field as 2018-10-10 as a date datatype.  Would like to convert to 20181010, but it should be integer datatype.  How can we achieve this by using tJavaRow?

 

Labels (3)
3 Replies
Anonymous
Not applicable

Be aware that if your date is Stored as a Date, it will hold the complete date down to milliseconds. The code below shows converting from a String format (not required here, but I needed to do this to demonstrate how to do what you want) to a Date, and from a Date to an int. 

 

//Set my date as a String
String date = "2018-10-10"; 
//Create my Date - Not necessary for you
Date myDate = routines.TalendDate.parseDate("yyyy-MM-dd", date);

//Convert my Date to an int
int myInt = Integer.parseInt(routines.TalendDate.formatDate("yyyyMMdd", myDate));

//Print out my int to prove it is correct
System.out.println(myInt);
rp2018
Creator
Creator
Author

The above commands worked fine when using tJavaRow and running the job.  But when I connect tJavaRow to tMSSqlOutput, I can't seem to sync the columns.  It puts the original source column instead of the column defined after converting it to int in tJavaRow.  What should I do to sync it?

Anonymous
Not applicable

You need to match the tMSSqlOutput schema with your tJavaRow output schema. Alternatively put a tMap between your tJavaRow and your tMSSqlOutput component. That will make it easier for you to connect your columns appropriately.