Converting h:mm:ss to hh:mm:ss

Im doing a school project and i need to transform a column that contains both hh:mm:ss and h:mm:ss into only hh:mm:ss. I have tried string manipulation, string to date time but nothing changes. I would apreciate if anywone could share a way to detect if a record only had 7 digits and add a 0 to the start. While i could do it in the file itself that wouldn’t add any value to my project.

Thank you.

event-notification-rpt-lastmonth.txt (124.3 KB)

Hi @Fonsy and wellcome to KNIME user forum.

Use nodes String to Date&Time with H:mm:ss then use Date&Time to String with HH:mm:ss

Fonsy.knwf (56.2 KB)

Best Regards

1 Like

alternatively,

what you are looking for is called “padding”. it can be used to add the needed amount of characters either at the beginning or end of a text string, to make them all at least n places long.

in this case, you could just padleft(column, 8, “0”)

3 Likes

No, you dont.
if its already 8 chars long, it will not add anything

2 Likes

Hi @Fonsy

@fe145f9fb2a1f6b is correct.

You don’t need to test for 7 chars. The solution is good and it is a better one.

Br

Thank you so much guys! I don’t know how i didn’t think of that :sweat_smile:. It works perfectly!

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