Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

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 
Labels (2)
4 Replies
Anonymous
Not applicable

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
_AnonymousUser
Specialist III
Specialist III
Author

Thank You. I will try this.
_AnonymousUser
Specialist III
Specialist III
Author

Thank you so much. Problem resolved. This worked perfectly.
Anonymous
Not applicable

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