Date Shifter - how to pass a negative day shift in a flow variable?

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

Try this. I’m using KAP 5.8.0. This workflow has both the current Date Shifter and its deprecated predessor. Both work.

Date Shift w Flow Variable.knwf (66.1 KB)

1 Like

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

But luckily there is 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”]))

1 Like

Did you look at my workflow? The Date Shifter node accepts negative flow variables.

1 Like

Yeah I did:
The Date Shifter is configured to use the “Offset” column to calculate the shift. No variable is used

Oh! Since you can enter negative values directly into the Shift value field, this looks like a bug to me. I opened a ticket (internal reference AP-25311).

For now, a 5.8 workaround might be to append a column with the value from the variable using Constant Value Column – KNIME Community Hub and than using that column in the Date Shifter.

For 5.5, I would recommend an expression-based solution as suggested by @ActionAndi using

add_date_duration($[“Date”], parse_date_duration($$[“delta_str”]))

Thanks for reporting,

nan

3 Likes

Hi all,

thank you very much for your fast support and workarounds. Meanwhile I used successfully the number column option with an additional column which is also feasible in my case. And of course it’s good to have the variable problem fixed in the next update.

2 Likes