Change 2 date format in a column

hey guys, I want to ask.
how can I change this format like in the picture, “yyyy.mm.dd” to “dd.mm.yyyy”? there are 2 date format, but i just want to change it in 1 format only.
gambar

example, the data is :
17.01.2022
2022.04.01

and I want the output like this,
17.01.2022
01.04.2022

thank you

Hello @takdirzd and welcome to the KNIME forum
A possible one node solution is String Manipulation with the following code:

string(
	regexMatcher($text$, ".*[.]\\d{4}").equals("True")
	? $text$
	: join(
		substr($text$, 8, 2)
		, "."
		,substr($text$, 5, 2)
		, "."
		,substr($text$, 0, 4)
		)
)

code source

image

Other possible approach would be Column Expressions…
With some more nodes you would be able to split the data based in a logical condition, modify target data, append back and resort if necessary.

BR

4 Likes

Hi guys…

Well you have a date problems, they are shuffle into a unique column, 2 different types.

If you’d like to be more simple, you can use the row split to separate the types A and B and make changes into one of them.

Thanks,

Denis

3 Likes

wow it works, thank you very much!

1 Like

yeah I think the same way. I can split them into 2 types date format, and merge them later. but I think it’s takes much time to do, and there will be a lot of nodes :smile: … thank you!

Yeap! I suggest to use regular expression for it… simple with string manipulation node:

regexReplace($$CURRENTCOLUMN$$,“(\d{4})\.(\d{2})\.(\d{2})”,“$3.$2.$1”)

I change the order with variables as $1.$2.$3 to $3.$2.$1

Just 1 node for it… and it’s secure because it’ll change if match the expression.

BR,

Denis

2 Likes

@denisfi you are right, I almost forgot regexReplace() is conditional itself.
Good catch!! :+1:t3:
regexReplace($text$, "(\\d{4}).(\\d{2}).(\\d{2})", "$3.$2.$1")
BR

1 Like

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