How do i convert different date format values to similar format in single column

I have date column having 2 different formats of date values like yyyy-MM-dd and dd-MM-yyyy . i need date values in single format only. how to do it in knime?

Hi,

I suggest using a Column Expressions node with this expression:

if (regexMatcher(column("column1"), "[\\d]{2}-[\\d]{2}-[\\d]{4}"))
regexReplace(column("column1"),"([\\d]{2})-([\\d]{2})-([\\d]{4})", "$3-$2-$1")
else column("column1")

:blush:

1 Like

Hi @armingrudd , thanks for reply…

Still having different formats only

image

There are 2 possibilities:

  • You have not checked to replace the column and a new column is created for the results.

  • There is a space character at the end of the strings. You can check this by selecting one of the cells and hold Ctrl and press “c” on your keyboard to copy the string and paste it somewhere to check if there is a space character at the end (or beginning). Best place to paste the string is inside the Column Expression so the space won’t be removed.

To solve the issue if the first case is right: check the “Replace Column” option.

To solve the issue if the second case is right: (a space character is added at the end of each regex pattern)

if (regexMatcher(column("column1"), "[\\d]{2}-[\\d]{2}-[\\d]{4} "))
regexReplace(column("column1"),"([\\d]{2})-([\\d]{2})-([\\d]{4}) ", "$3-$2-$1")
else column("column1")

:blush:

2 Likes

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