From string 2019/9/8 to date 2019/09/08

Hi all,
I can not figure out how to switch string 2019/9/8 to date 2019/09/08.

So far I’ve tried to use cell splitter to split 2019/9/8 to 3 columns which are year (like 2019), month (like 9) and day(like 8). Then I use rule engine to create a new column which is 0. Then I use string manipulation to join 0 and month, 0 and day. So it looks like 2019, 09, 08. But date like 2019/11/12 will looks like 2019, 011, 012. So I tried to keep last 2 characters of month and day column before join them together. And I haven’t figure out how.

Do anybody know how to keep the last 2 characters of a column?
And is there any easier way to transfer from string 2019/9/8 to date 2019/09/08?

Hi @Jocelyn

With the String to Date/Time (legacy) you can transform your date-string to a real date-field.
And with String Manipulation node it’s possible to extract the last two characters of your string.
See this last2.knwf (17.2 KB)
Knipsel

3 Likes

Thank you so much!! Your answer is super helpful!

1 Like

Hi @Jocelyn -

Here’s another suggestion for you. Since this question comes up fairly regularly - how do I deal with string-dates that don’t have leading zeroes, without using a legacy node? - I thought I would post a workflow on the Hub about it. You can get there with very few nodes once you know the trick, which is basically to set the format to something like:

M/d/yyyy

Note the single M and d in the format, which will actually handle double digit months and days too. Anyway, here’s the workflow:

2019-10-01%2012_31_54-KNIME%20Analytics%20Platform

4 Likes

Thanks so much sir. It’s very practical!!

1 Like

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