Concatenate String to String with a Condition with length

if(length(column(“MM”))=1){join(“0”,column(“MM”))}else{column(“MM”)}

I would like to add “0” to a column if it is one char long.

I would like to transform dates from 1120 to 01/01/2020, i have separated the values to “1” “1” “20” in different columns but need to modify them.

Rule Engine does not take lenght, and the expressions does not except the formula above ?

How can i proceed ?

Hi there @Ealikadioglu,

welcome to KNIME Community!

This seems a bit complex as you can have following combinations (dd/MM/yyyy assumed):

1120 --> 01/01/2020
10120 --> 10/01/2020
11020 --> 01/10/2020
101020 --> 10/10/2020

And if you have 11120 how do you know is it 01/11/2020 or 11/01/2020?

You can avoid conditions and use padLeft() function from String Manipulation node. It will add provided chars at beginning of string (“0” in your case) such that the length of the string equals the provided size (2 in your case) meaning zero will only be added in case string’s length is one.

Also to apply calculations and manipulations with conditions Column Expressions node can be used.

Br,
Ivan

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.