One Star

TalendDate.parse returns unexpected result

The following expression,
TalendDate.parseDate("yyyy-MMM-dd HH:mm:ss", "23-Mar-1979 23:59:59")
gives me the output:
Fri Jul 30 23:59:59 CET 28
I wonder why is it giving me such an output.

OS: Windows XP
Current Locale: Sweden
Talend ETL : 2.3.1
11 REPLIES
Employee

Re: TalendDate.parse returns unexpected result

Hi Umair,
You try to parse a Date with a String value but a wrong DatePattern.
When you parseDate you need to have the same Pattern for your String value to parse in a Date object your data.
Best regards;
One Star

Re: TalendDate.parse returns unexpected result

Why does the above example not throw an exception?
Rgds
Employee

Re: TalendDate.parse returns unexpected result

Normally, it's throw an exception.
Maybe umair has not written the same expression that wrong result displayed.
Best regards,
One Star

Re: TalendDate.parse returns unexpected result

The example, TalendDate.parseDate("yyyy-MMM-dd HH:mm:ss", "23-Mar-1979 23:59:59")
is quoted in TalendDate routine comments.
But, now i changed the values and tried with the updated params:
TalendDate.parseDate("yyyy-mm-dd HH:mm:ss", "1979-04-11 23:59:59")
It now gives :
Thu Jan 11 23:59:59 CET 1979
The month is displayed as something else
Employee

Re: TalendDate.parse returns unexpected result

It's because your pattern is wrong, for month use the MM and not the mm (mm is for minute) in your Pattern.
Best regards.
One Star

Re: TalendDate.parse returns unexpected result

yes, that worked.
Thanx for your help
One Star

Re: TalendDate.parse returns unexpected result

Hi,
I have a date in following format.
Tue Nov 01 12:36:40 GMT+05:30 2011
I tried to parse it using following statement in tJava component
TalendDate.parseDate("yyyy-mm-dd HH:mm:ss",input_row.mtime_string);
This input_row.mtime_string string comes from tfileProperties.
It returns following exception
Exception in component tJavaRow_1
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "Tue Nov 01 12:36:40 GMT+05:30 2011"
Whether am in missing something ?
Vaibhav
One Star

Re: TalendDate.parse returns unexpected result

Hi,
Solution to above query is following expression.
TalendDate.formatDate("yyyy-mm-dd hh:mm:ss",TalendDate.parseDate("EEE MMM dd HH:mm:ss Z yyyy","Tue Nov 01 12:36:40 GMT+05:30 2011"))
Contributed by Diwakar Nahata.
Thanks
Vaibhav

Re: TalendDate.parse returns unexpected result

Hi All,
TalendDate.ParseDate function in Talend to convert into Date Data type returns date in date data type but the date patterns is something else which is unexpected .
for eg.
I want to convert following string into date data type.
TalendDate.ParseDate("MM/dd/yyyy","09/18/2013")
The Above function returns me the date in date data type but the format of that is like "18-SEP-2013"
I want the output in "MM/dd/yyyy" means "09/18/2013" formats only.
can anyone suggest me how to overcome this issue.
Thank you in advance.
with kind regards,
Shailendra S.

Re: TalendDate.parse returns unexpected result

Hi All,
TalendDate.ParseDate function in Talend to convert into Date Data type returns date in date data type but the date patterns is something else which is unexpected .
for eg.
I want to convert following string into date data type.
TalendDate.ParseDate("MM/dd/yyyy","09/18/2013")
The Above function returns me the date in date data type but the format of that is like "18-SEP-2013"
I want the output in "MM/dd/yyyy" means "09/18/2013" formats only.
can anyone suggest me how to overcome this issue.
Thank you in advance.
with kind regards,
Shailendra S.
Community Manager

Re: TalendDate.parse returns unexpected result

Hi
Which is your output component? It is tLogRow? What's the date pattern on the schema? Set the date pattern to the format such as "MM/dd/yyyy" according to your need.

Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business