Change string to date format

#1

Dears,

I am new using Knime and I am facing below issue.
I have column which contanis date in this format Mar-2019 (actually it is string). I would like to change it to normal date format 2019-03-01
I have formated String to Date&Time with MMM-yyyy in date format


Hovewer I get this error

ERROR String to Date&Time 0:48 Execute failed: Failed to parse date in row '1.0_Row20: Text ‘Jul-2018’ could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {Year=2018, MonthOfYear=7},ISO of type java.time.format.Parsed

0 Likes

#2

Hi @Jedrek and welcome to the KNIME community,

I guess, you would need to attach the day (“01”) to your column and then use the String to Date&Time Node. I tried this by using the String Manipulator before and it works…
Z_010_data01.knwf (7.6 KB)

regards, Tommy

2 Likes

#3

Hi @tommy,
Thank you for replay. Unfortunately it didn’t work, because some row contain NULL values. Is it possible to add if statement to String Manipulation?

0 Likes

#4

hi @jedrek,
not in the String Manipulation, however you may use a Row splitter (Row filter) Node in order to exclude the NULL values first.

Top Output Port contains valid rows, Bottom Output Port the “Nulls” / missing values.

0 Likes

#5

Hi there @jedrek,

also you can unckeck Fail on error option in String to Date&Time node. This will create missing value from any value that can not be parsed.

FailOnError

Br,
Ivan

2 Likes

#6

hi @ipazin
Thank you for your replay, it has worked but I got “?” instead of empty values.
Can I get NULLs insted?
image
I have tried to use string manipulation, but “?” are still there
replace($Month$,"?","")

0 Likes

#7

Hi @jedrek,

to deal with missing values there is Missing Value node so check him out. Also you can use Rule Engine node with following expressions:

MISSING $column_name$ => “NULL”
TRUE => $column_name$

Don’t think String Manipulation node can deal with missing values.

Br,
Ivan

0 Likes

#8

Thank you, apparently after saving file, there were no “?” Just empty values

0 Likes

#9

Hi,

red question mark in KNIME means missing value :wink:

Br,
Ivan

1 Like