Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

String to date conversion

Hi,

 

So, I've source string in the format 'MMddyyyy'("12012016") and I want to convert it into date 'MM-dd-yyyy'.

Is there a function in talend to convert this type? I used  TalendDate.parseDate("MM-dd-yyyy",source.column) and its throwing-- Unparseable date: "12012016"  error.

 

Any suggestions?

 

Thanks in advance

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

It is all string manipulation. You can also do something like the below:

yourDate.substring(0,2) + "-" + yourDate.substring(2,2) + "-" + yourDate.substring(4,4)

View solution in original post

6 Replies
Anonymous
Not applicable
Author

You can simply add "-" to each of the necessary positions.

Anonymous
Not applicable
Author

In that scenario, the output will be still a string type not date, isn't it?

Anonymous
Not applicable
Author

TalendDate.formatDate("MM-dd-yyyy", TalendDate.parseDate("MMddyyyy",yourDate))

 

That is what you want.

Anonymous
Not applicable
Author

It is all string manipulation. You can also do something like the below:

yourDate.substring(0,2) + "-" + yourDate.substring(2,2) + "-" + yourDate.substring(4,4)

Anonymous
Not applicable
Author

Thankyou!

It worked, I guess that is the only method, any other suggestions are welcome.

 

BTW slight correction in substring expression

yourDate.substring(0,2) + "-" + yourDate.substring(2,4) + "-" + yourDate.substring(4,8) as var1

 

and later I used TalendDate.parseDate("MM-dd-yyyy",Var.var1)

Anonymous
Not applicable
Author

You're welcome. Thank you for the correction. I was doing it off memory so I apologize for the error. I was trying to beat others to the solution.

You could use TalendDate solution as well:


TalendDate.formatDate("MM-dd-yyyy", TalendDate.parseDate("MMddyyyy",yourDate))