Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I'm trying to extract dates by inserting them into variables context. Everything works as long as it's just insertion.
But I would like to make a calculation: remove 3 months to the date and store it in another variable with tJavaRow and tDBOracleInput (Date pattern "dd/MM/yyyy")
my tJavaRow :
context.MaxDateCreation = input_row.MAX_DATECREATION; context.MaxDateSoldeCompta = input_row.MAX_DATESOLDECOMPTA; context.MaxDateSoldeCompta_3M = TalendDate.addDate("context.MaxDateSoldeCompta","dd/MM/yyyy",-3,"MM"); System.out.println(context.MaxDateCreation); System.out.println(context.MaxDateSoldeCompta); System.out.println(context.MaxDateSoldeCompta_3M);
But I get this error : Error : type mismatch: cannot convert from String to Date
I tried this :
TalendDate.addDate(TalendDate.parseDate("context.MaxDateSoldeCompta","dd/MM/yyyy"),"dd/MM/yyyy",-3,"MM");
Error : The method addDate(String, String, int, String) in the type TalendDate is not applicable for the arguments (Date, String, int, String)
So I tried this
TalendDate.addDate(TalendDate.parseDate("context.MaxDateSoldeCompta","dd/MM/yyyy").toString(),"dd/MM/yyyy",-3,"MM");
But I fall back on the initial error 😕
So my last try was this :
context.MaxDateSoldeCompta_3M = TalendDate.parseDate(TalendDate.addDate("context.MaxDateSoldeCompta","dd/MM/yyyy",-3,"MM"),"dd/MM/yyyy");
Exception in component tJavaRow_1
java.lang.RuntimeException: dd/MM/yyyy can't support the date!
My output of my others variables without calculation:
Output Wed Aug 01 01:44:43 CEST 2018 Tue Jul 31 00:00:00 CEST 2018
Datatype of my variables is 'Date' (without others specification).
What is the correct synthax to get what I want ?
Thanks
Hi,
My first assumption is that you are having the context variable context.MaxDateSoldeCompta in date format. In that case, you will have to use the expression as below to get the 3 month older date.
TalendDate.addDate(context.input_date,-3,"MM")
Warm Regards,
Nikhil Thampi
You're passing a string literal to the addDate method. You should remove the double quotes.
context.MaxDateSoldeCompta_3M = TalendDate.addDate(context.MaxDateSoldeCompta,"dd/MM/yyyy",-3,"MM");
Hi,
You re giving the context variable itself in double quotes as "context.MaxDateSoldeCompta". So instead of consumed as a variable, it is consumed as a String.
Warm Regards,
Nikhil Thampi
When I remove the quote "", I had the 2nd error :
Error : The method addDate(String, String, int, String) in the type TalendDate is not applicable for the arguments (Date, String, int, String)
I can't see where the problem comes from, other than the format of the date
Wed Aug 01 01:44:43 CEST 2018
This kind of output look very special, however in my DB it display like that "dd/MM/yy"
I also tried - instead of /, yy instead of yyyy but always same issue
Hi,
My first assumption is that you are having the context variable context.MaxDateSoldeCompta in date format. In that case, you will have to use the expression as below to get the 3 month older date.
TalendDate.addDate(context.input_date,-3,"MM")
Warm Regards,
Nikhil Thampi
OMG it was so simple. And when I think I was trying to convert my Date format into a String
Thanks
Hi,
No problem at all. Happy to help.
Enjoy Talend 🙂
Warm Regards,
Nikhil Thampi