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)

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

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

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

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

Download