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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to concatenate string with filter in tmap

Hi,
I have a date column like
02/23/2013
04/23/2013
02-23-2014
dates are in different format so to take the column in one format (MM-dd-YYYY) i used tReplace and replaced "/" with "-"
but know the output dates which are replaced are like for 02/23/2013 output is 2-23-2013 so
How do I concatenate a "0" to all the dates which are converted .
Labels (2)
6 Replies
willm1
Creator
Creator

If your input field is of type string, you shouldn't have to have the issue you're having... The replace shouldn't remove leading zeros... See attached...
(Alternatively, you can use a java date parse function to convert what you currently have...)
0683p000009MDOb.png 0683p000009MDBY.png
Anonymous
Not applicable
Author

hi,
as you need to know which pattern is used before replace caracter, you can try the tFilterRow in advenced mode and check String contains "-" ; if OK do something
Else , use reject flow , check if contains "/" ....etc
here an example to convert String to Date without using too many java code by Talend components. (it will be more readable 0683p000009MACn.png
regards
laurent
0683p000009MDHh.png
willm1
Creator
Creator

@kzone - I like your solution as well, but want to point out that the replace function will only replace if it finds a delimiter - so the code is lighter - no need for filtering for it... Sometimes leveraging java functions is more efficient and equally elegant...
If my example seemed like overkill (and overwhelming), here's the output field that should work for all fields:
(strDate1.toString()).replace("/", "-")
It first makes sure it's a String, then replace any occurences of / with -
Anonymous
Not applicable
Author

It's not the fact that java code is more elegant or not 0683p000009MA9p.png
Using 'Talend graphic langage', I'm able to also use any statistics information about meterflow or catch reject about filter, etc.
If I have some evolutions or modifications, I can easily do it by adding some extra "Talend code".
By using java code, I have to add some new extra java code to modify behavior.
In my example, I've got some java code with contain method, but inherent to filter component.
It's one of reasons that I'm using java code as few as possible even if it could be elegant 0683p000009MACn.png
But it's not a priesthood 0683p000009MA9p.png
regards
laurent
Anonymous
Not applicable
Author

Thanks Willm and kezone !!!
@willm my input field is string and I use tReplace component to replace the "/" with "-" but actually i missed to mention that my source column did not had leading zeros for dates with "/" format.
but I used a different solution : After replacing the "/" with "-" . In tMap I used an expression as below which worked !!!
(row3.Date.length())==9)?"0"+row3.Date : row3.Date
willm1
Creator
Creator

Awesome, pkakade! Glad you got it to work...
kzone - I totally understand what you're saying about using Talend out-of-the-box components and methods than using Java... I hear you... Yes, when you need to expose stats, Talend components are the way to go. My suggestion of that tiny java snippet was intended for the tMap component which doesn't interfere much with things before and after it...
But I agree - data integration is both an art and a science... 0683p000009MACn.png