Search code examples
etltalend

Unable to convert string into date in tMap component Talend


I have gone through some similar questions but those solutions didn't worked for me I am having a date field which is String of timestamp "1631898440" I tried converting this string into date using tMap but got this error - java.lang.RuntimeException: java.text.ParseException: Unparseable date: "1631898440".

The function I am using -

row5.mydatecolumn!=null && !"".equalsIgnoreCase(row5.mydatecolumn)? TalendDate.parseDateLocale("EEE MMM dd HH:mm:ss zzz yyyy", row5.mydatecolumn, "EN") :null 

Also tried -

TalendDate.parseDate("ddMMyyyy",row5.mydatecolumn)

In this I am getting this err- timestamp out of range: "898442-07-16 00:00:00+05:30"ERROR

How to resolve this issue is there anything wrong with the format of date?


Solution

  • In your user routine just create a fonction like this :

     public static Date Convert_String_To_Date(String String_Timestamp) {
            
            SimpleDateFormat sf = new SimpleDateFormat("ddMMyyyy");
            Date date = new Date(Long.parseLong(String_Timestamp));
            System.out.println("*** Date Converted to this patter ddMMyyyy : "+sf.format(date));
            return TalendDate.parseDate("ddMMyyyy",sf.format(date)) ; 
        }
    

    don't forget the import

    import java.text.SimpleDateFormat;
    import java.util.Date;
    

    then for me i just put a tjava component where i called my fonction like below

    String str = "1631898440";
    System.out.println(Format_String_Date.Convert_String_To_Date(str)) ; 
    

    So , in your case you would call this fonction in your tMap like this i guess :

    row5.mydatecolumn!=null && !"".equalsIgnoreCase(row5.mydatecolumn)? 
    Format_String_Date.Convert_String_To_Date(row5.mydatecolumn) :null 
    

    Here is the output

    [statistics] connected
    *** Date Converted to this patter ddMMyyyy : 19011970
    Mon Jan 19 00:00:00 CET 1970
    [statistics] disconnected