One Star

Parse String to Date

Hi All,
I have situation where I want to convert String to Date.
I tested first without parsing anything. It looks like this :

Source : 8/5/2012 3:27:06 PM
Result : Tue May 08 15:27:06 SGT 2012

Mind you that both are Strings.
Do you have any idea on how to convert String to Date. So that the Result datatype is Date not String.
Thanks in advance,
One Star

Re: Parse String to Date

hi sonal,
I Have tried using TalendDate.parseDate("dd/MM/yyyy HH:mm:ss",row1.Value) and the result is
Starting job UC_Pro_Preparation at 09:27 08/02/2013.

connecting to socket on port 3935
Exception in component tMap_1
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "row1.pa_record_create_date"
at routines.TalendDate.parseDate(
at talend.uc_pro_preparation_0_1.UC_Pro_Preparation.tFileInputExcel_1Process(
at talend.uc_pro_preparation_0_1.UC_Pro_Preparation.runJobInTOS(
at talend.uc_pro_preparation_0_1.UC_Pro_Preparation.main(
Caused by: java.text.ParseException: Unparseable date: "row1.pa_record_create_date"
at java.text.DateFormat.parse(Unknown Source)
at routines.TalendDate.parseDate(
... 3 more
Job UC_Pro_Preparation ended at 09:27 08/02/2013.
Do you have any idea what is going wrong with the job?
Thank you.
One Star

Re: Parse String to Date

Hi Naim,
One of the method to achieve this is by changing the data type from the edit schema option.
# Double click on the tLogRow Component
# Click on the edit schema option
# Select the column which data type needs to be change
# Change the data type form the drop down list available in the type column
# Make these change in both the ends i.e. tLogRow as well as tFileInputExcel
# You can also mention the desired pattern of the date in the Date pattern column
For more details have a look in the attached snapshot.
Best Regards,
One Star

Re: Parse String to Date

These examples work:
TalendDate.parseDateLocale("d/M/yyyy HH:mm:ss a",
"8/5/2012 3:27:06 PM","EN")
TalendDate.parseDateLocale("EEE MMM dd HH:mm:ss z yyyy",
"Tue May 08 15:27:06 SGT 2012","EN")

for your source, you would use:
TalendDate.parseDateLocale("d/M/yyyy HH:mm:ss a",row1.pa_record_create_date,"EN")
One Star

Re: Parse String to Date

Thank you so much.