Issue in converting Date format yyyy to int

Four Stars

Issue in converting Date format yyyy to int

There is a mySQL variable in "YEAR" datatype i.e. present in "yyyy" and I would like to convert it as int through Talend.

I use tMap with expression function formatDate to convert the type as str and then use tConvertType compo to convert the str as int. When I look up the result by tLogRow. the variable is unable to represent with error java.text.ParseException: Unparseable date: "2004". How can I solve the issue?

Eight Stars

Re: Issue in converting Date format yyyy to int

Assuming you have the correct syntax of TalendDate.formatDate(), are you sure the year column is on the database as a date type and the schema within Talend is a date time?

 

Thanks

 

David

Regards

David

Don't forget to give Kudos when an answer is helpful or the solution.
Four Stars

Re: Issue in converting Date format yyyy to int

Check to make sure the input is a valid date format then use.

 

TalendDate.getPartOfDate("YEAR",yourdate)

 

This returns an INT type without the need of the tconverttype