Formatting date/time from variable

I’m using a Date and Time Widget to generate a variable which I can pass to a String Manipulation node in order to append a date/time to a filename. I was using the widget since I want this to update each time I execute the flow.

This works, but the date/time isn’t in the format I’d prefer.

To fix, I attempted to turn the variable into a table row then convert the string to a date/time to try and modify the format, however this wasn’t recognised. Even though this didn’t work, my solution seems a bit convoluted.

Is anyone able to tell me the best way to go about this, being able to get the date/time in a YYYY-MM-DD_hhmm format?

Hello @knime_a,

Welcome to the world of KNIME.
You might think of using the mentioned Date and Time Widget followed by a Variable Expressions Node https://nodepit.com/node/org.knime.expressions.base.node.variableexpression.VariableExpressionsNodeFactory using this expression

substr(variable("date-input"), 0, 10)+"_"+substr(variable("date-input"), 11, 2)+substr(variable("date-input"), 14, 2)

That could bring an answer for your problem.

3 Likes

knimedigers solution is certainly the best (thanks for sharing)
another option could be
dateformat

1 Like

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