Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am passing a date value to a global variable and then trying to print it to the screen using tJavaRow:
System.out.println(globalMap.get("MaxInsertDateTime"));
and this prints fine - here is the output:
2019-07-15T03:46:02
However what I would like to do is format the value to "YYYY-MM-DD" format. I tried multiple different ways to do it but no luck so far:
System.out.println(TalendDate.formatDate("YYYY-MM-DD",(globalMap.get("MaxInsertDateTime"))));
Error:
Detail Message: The method formatDate(String, Date) in the type TalendDate is not applicable for the arguments (String, Object)
I also tried this:
System.out.println((String)globalMap.get("MaxInsertDateTime"));
Error:
java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String
What am I doing wrong here?
My goal is to format the date as "YYYY-MM-DD" and then use it later in tMSSQLInput component in a where condition.
Hi,
The message is telling you what's wrong :
The method formatDate(String, Date) in the type TalendDate is not applicable for the arguments (String, Object)
Java doesn't know that your globalMap.get("MaxInsertDateTime") object is actually a date, so it takes it as an Object and cannot use formatDate on an Object.
You have to explicitly tell that globalMap.get("MaxInsertDateTime") is a Date (assuming it *is* a date of course).
If you setup your global variable correctly, this should work :
System.out.println(TalendDate.formatDate("yyyy-MM-dd",(Date)globalMap.get("MaxInsertDateTime")));
btw: Talend corrects the misuse of upper/lower case in the date format but I strongly suggest you to use the proper case (see SimpleDateFormat for the detail)
Regards