How to use TalendDate.parseDate() to convert from string to date

One Star

How to use TalendDate.parseDate() to convert from string to date

Hi,
I have a date(String data type) column in mysql table , values are in 2 formates 'yyyyMMdd_hhmmssSSS' and 'yyyy-MM-dd hh:mm:ss'.
I can convert this string type to date using TalendDate.parseDate("yyyyMMdd_hhmmssSSS",row1.date);
this conversion i am using inside a tMap component. My question is How to use TalendDate.parseDate() for both the date formates at once?
Right now I am getting unparsable date formate error since I am not handling this 'yyyy-MM-dd hh:mm:ss' format. Please help.
Thanks 
Five Stars

Re: How to use TalendDate.parseDate() to convert from string to date

If understood correctly you have a column called row1.date which has two different type of dates, in single column? 
then you can do it in following way. 
row1.date.contains("_")? TalendDate.parseDate("yyyyMMdd_hhmmssSSS",row1.date): row1.date.contains(":")? TalendDate.parseDate("yyyy-MM-dd hh:mm:ss",row1.date):TalendDate.getDate()

Try this one or you can check more date formats on talend-date-routine-function-with-examples
One Star

Re: How to use TalendDate.parseDate() to convert from string to date

Thank You. I will try this.
One Star

Re: How to use TalendDate.parseDate() to convert from string to date

Thank you so much. Problem resolved. This worked perfectly.
Five Stars

Re: How to use TalendDate.parseDate() to convert from string to date

Happy to see it works.. you can now closed this topic, mark it Resolve.