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)
1 Solution

Accepted Solutions
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

View solution in original post

32 Replies
Anonymous
Not applicable

use below code.
TalendDate.parseDate("yyyyMMdd",row1.column1) 
soujanyam
Contributor
Contributor
Author

Thanks for your prompt reply umesh.
I tried even that also. But it didn't works. Would you suggest more ideas?
Can I write if else condition in tMap to take any value either yyyyMMdd format or yyyy-MM-dd format and then to insert into output column as date with yyyy-MM-dd format? If so How should I implement this?
Any help would be appreciated.
Thank you.
Anonymous
Not applicable

output will not ask you for specific format, it will required only Date object, If you show me input string from your file then I can suggest you better.
soujanyam
Contributor
Contributor
Author

Thanks for your reply. The input column is as below.
Date
2014-12-21
20140214
2014-12-13
2014-12-23
20141201
The output should be in yyyy-MM-dd fromat only whatever may be the input format.
Anonymous
Not applicable

So you have two formats in single column. then you can use below logic which help you. 

yourcolumn!=null && yourcolumn!=" "?
TalendDate.parseDate("yyyyMMdd', yourcolumn.replaceAll("-", "")):null

this will solve your problem.
soujanyam
Contributor
Contributor
Author

Thanks for your prompt reply.
Sorry Umesh I forgor to tell you onemore thing.
I also had -1,-2 values in that same column.That above problem is solved with TalendDate.parseDate("yyyyMMdd",row1.Column1).
Now the problem is with -1,-2 values. I've to place 0000-00-00 in output column when I get those values from input file.
How could I do this?
Thanks you
Anonymous
Not applicable

You can do in the same way, you have to check the length of column if it is less than expected then replace with, desire string. 
soujanyam
Contributor
Contributor
Author

Thanks for your reply Umesh. But I didn't get you. Where to check the length of column?
Anonymous
Not applicable

check the length of the column in same code.
yourcolumn!=null && yourcolumn!=" " && yourcolumn.length>68? 
TalendDate.parseDate("yyyyMMdd', yourcolumn.replaceAll("-", "")):TalendDate.parseDate("yyyyMMdd', "000000")