Date Difference function in "Column Expression" node

Hello Everyone,
I have a quick question. Just want to see if there is any function in “column expression node” which can give me a date difference. Example - i have two date column. I want to find the difference in days from those two column. I have added a snap shot from different ETL tool where I used to perform similar operation in their equivalent tool.

In the snap shot below, i pass a condition in the function and if it is true pass one value or else pass the other value. On of the argument is getting a result from the datedifference function.

For now i am using the “Date & time difference” node to achieve the below condition. However, i need to do this multiple time with multiple different condition. Was hoping to find something that i can use it in column expression tool.

Thank you.

Knime Forum

Hi @tamzid89

Welcome to the KNIME Community!

If you really want a one-node solution, you are better off with a Java Snippet in this case. It’s similar to the Column Expression but has a bit more features.

Let’s assume this sample:

image

If you want to calculate to difference based on the number of days, you can use:

int diff = Math.abs(c_OrderDate.until(c_Today).getDays());

Output:

If you then want to use the value for comparison in accordance with your rules you can directly set up an if-else structure. To illustrate:

int diff = Math.abs(c_OrderDate.until(c_Today).getDays());

if (diff < 7) {
	out_output = 2;
} else if (diff < 14) {
	out_output = 1;
} else {
	out_output = 0;
}

You’ll see that, based on the ruleset, the corresponding number is applied to that row.

See WF:
Date Difference function in “Column Expression” node.knwf (13.2 KB)

Hope this helps!

2 Likes

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