Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
soujanyam
Contributor
Contributor

[resolved] cannot convert string to date in tMap

Hi everyone.
I've the csv file in which one column has date (which is defined as Number in csv file) but in tFileInpuDelimited it read as string in which some of the vales are like 20140424 and some are like 2014-04-25 in the same column.I've to parse this data into output component( tOracleOutput)as date column.So I tried to convert the string to date by using 
TalendDate.parseDate("yyyy-MM-dd",TalendDate.formatDate("yyyy-MM-dd",row1.column1)) and changed the output column as date with format yyyy-MM-dd.
Then I'm getting error as 
Unparseable date: "20140424".
How could I parse this into output component?
Any help would be greatly appreciated.
Thank you in advance.
Labels (3)
32 Replies
soujanyam
Contributor
Contributor
Author

Thank you but if I had different data formats in input column how to parse it.
When input has only two formats "20140224" or "2014-02-24" by using TalendDate.parseDate("yyyyMMdd",row1.Column1), data is parsing to the output.
When date includes  "02/24/2014" with above formats,
I used in tMap as
TalendDate.isDate(row1.Column1,"MM/dd/yyyy")?TalendDate.parseDate("yyyy-MM-dd",Column1):TalendDate.parseDate("yyyyMMdd",row1.Column1))
then could not parse the data.Getting error as
Caused by: java.text.ParseException: Unparseable date: "02/24/14"
What could I do?
Thank you
Anonymous
Not applicable

First get a list of formats then do above logic for replace and then do the parsing that will help. use each parsing according to source format. 
if there are multiple formats then create routine and write all the check and validation to handle date conversion, and then return date object form routine function. this is the best way for you.
soujanyam
Contributor
Contributor
Author

Ya I've checked the source data format. It has the above three formats only. So how could I handle?
What should I modify in the function which I've used
TalendDate.isDate(row1.Column1,"MM/dd/yyyy")?TalendDate.parseDate("yyyy-MM-dd",row1.Column1):TalendDate.parseDate("yyyyMMdd",row1.Column1))
Please provide the solution to me. I'm eagerly waiting for the solution.
Thank you.
Anonymous
Not applicable

try this.
yourcolumn!=null && yourcolumn!=" " && yourcolumn.length>68? yourcolumn.contains("-")?
TalendDate.parseDate("yyyyMMdd', yourcolumn.replaceAll("-", "")):TalendDate.parseDate("MM/dd/yyyy', yourcolumn):TalendDate.parseDate("yyyyMMdd', "000000")
Anonymous
Not applicable

Hi Umesh,
I have situation that, I have source table with 2 columns as follows..
START_DT           NAME
01/12/2015         PANKAJ
02/27/2010         SURAJ
START_DT has string datatype in source table but i just want it in DATE datatype without changing its values format.
how i can achieve that? give solution..
thanx in advance.

Regards,
Shri_Kul1
Talend User.
Anonymous
Not applicable

Hi Shri_Kul1,
You can use built-in function TalendDate.parseDate(string date_pattern, string string_of_date) to convert String to Date in tMap.

Best regards
Sabrina
Anonymous
Not applicable

Hey Hi,
could you please give me example with that logic you mentioned.
Regards,
Shri_Kul1
Anonymous
Not applicable

Hey ,
Thanks for your valuable reply , its working .... Thanks a Lot.
Regards,
Shri_Kul1
Talend User.
Anonymous
Not applicable

Hi Shri_Kul1,
Please take a look at my screenshot.
Feel free to let us know if it is what you are looking for.
Best regards
Sabrina
0683p000009MBPu.png
Anonymous
Not applicable

Hi,
Exactly, i have done as posted in screen shot.
Thanks Sabrina for your valuable feedback.

Regards,
Shri_Kul1
Talend User.
0683p000009MBn7.png