Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
gusilu
Contributor
Contributor

Parsing string date from a filename

Hello,

 

I have a file with the following format:

 

203147_TMBreakdown_Aug29_2018-Aug31_2018_20180901

204780_TMBreakdown_Sep17_2018-Sep18_2018_20180920

 

I'd like to parse out the first date in the filename as YYYY-MM-DD or DD/MM/YY

 

In the two filenames above:

 

Aug29_2018 ----> 2018-08-29 or 29/08/18

Sep17_2018 ----> 2018-09-17 or 17/09/18

 

Could anyone help me on how to do this? I'm fairly new to Talend. 

 

Thanks

Labels (2)
2 Replies
Anonymous
Not applicable

If you can guarantee your incoming format will always be consistent the following will work in a tJavaRow component:

String data = row1.data;
row2.start = data;

//extract date from string
String extracted = data.substring(data.indexOf("_",data.indexOf("_") + 1) + 1,data.indexOf("-"));
row2.extracted = extracted;

//extract date formatted
Date d = TalendDate.parseDate("MMMdd_yyyy", extracted);

row2.finalDate = TalendDate.formatDate("yyyy-MM-dd", d);

0683p000009M09Q.png 

gusilu
Contributor
Contributor
Author

Thank you so much! I will try this as soon as I get home.

 

Thanks again