Icon

251111_​negativeDateShift

Hi all,

how can I pass a negative day shift (e.g. minus 2 days) by a flow variable into the date shifter node?

I tried -2d or -(2d) or -(2 days) but always got parsing errors. However positive shifts (e.g. 2d, 5d, …) worked fine.

We are using KNIME version 5.5.1.

Thanks in advance for any ideas

It’s a pity that the Date Shifter cannot negative values from variable inputs.

But luckily there the Expression node.

With “add_date_duration($[“Date”], parse_date_duration(“P-1D”))” it’s possible to substract a day from you date column.

So the only thing to do is to use the convert the integer value of the offset into a string with the prefix “P” and suffix “D”. This is done in the “string manipulation (variable)” node:

string(“P”)+string($${IDelta}$$)+string(“D”)

and pass it into the “Expression” node:
add_date_duration($[“Date”], parse_date_duration($$[“delta_str”]))

Date&Time Range Creator
String Manipulation (Variable)
Variable Creator
Expression
Date Shifter

Nodes

Extensions

Links