How to convert numbers with different digits in a column into time

I tried to convert a column of String into time formate. How can I deal with the
“ERROR String to Date&Time 3:16 Execute failed: Failed to parse date in row 'Row0: Text ‘0758’ could not be parsed at index 2”.


The result I wish to get like " HH:MM" How can I solve it? Thank you.

Hello @smilewz911 and welcome to the KNIME Forum

Please find attached a proposed solution to your challenge:

image

20220325_string_to_time_v1.knwf (29.6 KB)

The Output Column Format is ‘Time’, seconds are not displayed because they are == 0

BR

3 Likes

Hi @smilewz911 and welcome to the Knime Community.

Something like this should do:
image

I used this expression to format the time:
join(substr(padLeft($DEPARTURE_TIME$, 4, "0"), 0, 2), ":", substr(padLeft($DEPARTURE_TIME$, 4, "0"), 2, 2))

And it manipulates the given data into the proper time format:
image

After that, just convert the formatted time into a column of type time:
image

Here’s the workflow: Convert numbers with different digits into time.knwf (9.7 KB)

4 Likes

Thank you so much. I love your solution.

1 Like

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