Search code examples
mysqlparsingdatetalend

Talend MySql String To MySql Date for storage and difference calculations


I have a MySql table with a String 2014-02-21 16:53:01 stored in a varchar column. I need to use Talend Data Integration to convert it into a date for calculations in the format dd/mm/yyyy hh:mm:ss and to store it in that format in another MySql as a date column after the calculations.

I have a talend tmap component but I get parsing errors and not sure how to solve it and the general sequence of steps needed.

In the tmap I have a variable with the expression

row1.date !=null ? TalendDate.parseDate("dd/mm/yyyy hh:mm:ss",row1.date):null 

Which I hope will load the variable wiIs that the best way to

  1. Convert the string in the source table to a date in the format I need?
  2. How do you handle null dates as I need to get the difference between 2 dates but handle the situation where 1 or both may be blank or null
  3. How do I get the destination table to store the date in the format I need? I have the Date Pattern supplied in the destination tmap schema but is that enough if the date format is yyyy-mm-dd ?

Any Talend experts able to help a novice out?


Solution

  • For better control on null check I recommend you to use below function.

    !Relational.ISNULL(row1.date) && !"".equalsIgnoreCase(row1.date) ?TalendDate.parseDate("MM/dd/yyyy HH:mm",row1.date):(null or default date);
    

    if you are doing any operation on date? then don`t supply null as a result because you may get error on next component.

    always pass default value so that you can check in next component and ignore it or store it based on business need.