String to date conversion

Six Stars

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


Accepted Solutions
Six Stars

Re: String to date conversion

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)

Six Stars

Re: String to date conversion

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)


All Replies
Six Stars

Re: String to date conversion

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

Six Stars

Re: String to date conversion

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

Six Stars

Re: String to date conversion

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

 

That is what you want.

Six Stars

Re: String to date conversion

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)

Six Stars

Re: String to date conversion

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)

Six Stars

Re: String to date conversion

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

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.