# Date Difference function in "Column Expression" node

**URL:** <https://forum.knime.com/t/date-difference-function-in-column-expression-node/49848>\
**Category:** KNIME Analytics Platform\
**Created:** [December 2, 2022, 6:04pm UTC](https://forum.knime.com/t/date-difference-function-in-column-expression-node/49848 "2022-12-02T18:04:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamzid89](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/t/898d66/32.png) [@tamzid89](https://forum.knime.com/u/tamzid89)\
**Post date:** [December 2, 2022, 6:04pm UTC](https://forum.knime.com/t/date-difference-function-in-column-expression-node/49848/1 "2022-12-02T18:04:20Z")

</div>

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](https://forum-cdn.knime.com/uploads/default/original/3X/6/a/6aad9c20e0a77cfecac99182ef8c748fea5129fa.png)

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [December 2, 2022, 7:25pm UTC](https://forum.knime.com/t/date-difference-function-in-column-expression-node/49848/2 "2022-12-02T19:25:21Z")

</div>

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](https://forum-cdn.knime.com/uploads/default/original/3X/0/a/0a7ca8757885bbe63461f999a175728f28e1b559.png)

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:

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/a/f/af3d90e74eefaee299bd9de69375d8dee976a76c.png)

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:

```auto
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.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/4/f/4f19df875f0b494333c9dcf83eb13765d555576f.png)

See WF:  
[Date Difference function in “Column Expression” node.knwf](https://forum.knime.com/uploads/short-url/uuPFjrr3Cj8HkMsyTgFRK7neGVW.knwf) (13.2 KB)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [December 13, 2022, 4:57pm UTC](https://forum.knime.com/t/date-difference-function-in-column-expression-node/49848/3 "2022-12-13T16:57:08Z")

</div>

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