type mismatch : cannot convert from string to date

One Star

type mismatch : cannot convert from string to date

hello,
i need to set previous day date to fetch my previous day status records so i used this code .

" TalendDate.formatDate("yyyy-MM-dd", TalendDate.addDate(TalendDate.getCurrentDate(), - 1, "dd")) "
by this code im getting previous day date but only in "string" format in stage variables but i want it in "date" format
if i changed that to "date" format it shows error like " type mismatch : cannot convert from string to date " .
how can i get the same in "date" format ? can anyone suggest me for this?

Thanks in advance
Nilesh
One Star

Re: type mismatch : cannot convert from string to date

can anyone help me for this issue asap?
Community Manager

Re: type mismatch : cannot convert from string to date

Hi
The method formatDate returns a String, if want a date format, use this expression:
TalendDate.addDate(TalendDate.getCurrentDate(), - 1, "dd")
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: type mismatch : cannot convert from string to date

for that im getting like
"Wed May 25 14:58:56 GMT+05:30 2011"
but i need a output like "2011-05-25" in date format.
Community Manager

Re: type mismatch : cannot convert from string to date

Hi
Change the data type of column on schema to String, then you are able to use the expression as below to formate a Date to a String.
TalendDate.formatDate("yyyy-MM-dd", TalendDate.addDate(TalendDate.getCurrentDate(), - 1, "dd"))
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: type mismatch : cannot convert from string to date

Ya this is what i used earlier .
now i need the same result(2011-05-18) but the datatype should be in date format because i need to merge it with my data which is in "date" datatype ..
Is "2011-05-18" format in "date" data type in talend tool....
Community Manager

Re: type mismatch : cannot convert from string to date

Hi
Is "2011-05-18" format in "date" data type in talend tool....

Yes, just set the date pattern as "yyyy-MM-dd", it will looks like "2011-05-18" in target.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: type mismatch : cannot convert from string to date

yes i can change the format but if the data type is "date" it showing the same type mismatch error.
One Star

Re: type mismatch : cannot convert from string to date

TalendDate.parseDate