# Calculate Date&Time Difference only if condition is met

Hi all,

I’m trying to calculate Date&Time Difference between two columns but only when some other column’s value is “YES”.

For instance:

DATE 1 | DATE 2 | CONDITION | DIFFERENCE
apr-30 | may-1 | YES | 1
apr-12 | may-2 | NO |
apr-25 | apr-30 | YES | 5
apr-20 | apr-30 | NO | 10

I tried using flow variables but apparently the Date&Time Difference node does not accept this kind of variable.

Thank you so much in advance.

Hi @lblanc

Use a row splitter to separate YES from NO.

Then applay date time diference on YES rows.

Then concatenate rows.

Br

6 Likes

Hi @lblanc, @hmfa’s solution should work but based on the sample data you supplied, you will first need to convert your data so you actually have proper dates in it. (i.e. you will need to include a year).

On the face of it, that sound relatively simple as you could perhaps append a year value to the DATE1 and DATE2 columns and then use String to Date&Time but there is complexity over what year to append in each case.

e.g. you might need to append the same year if it is
DATE 1 | DATE 2 | CONDITION | DIFFERENCE
apr-30 | may-1 | YES | ?

but different years if it is
DATE 1 | DATE 2 | CONDITION | DIFFERENCE
dec-30 | jan-1 | YES | ?
jan-2 | dec-1 | YES | ?

and do you append a leap year or a non-leap year if it is
DATE 1 | DATE 2 | CONDITION | DIFFERENCE
feb-27 | mar-2 | YES | ?

2 Likes

Hi @lblanc,

a few more things were required as your data is not quite compatible for processing.

Best
Mike

3 Likes

Hey guys,

I managed to make it work with row splitter + concatenate. Seems simple enough.

Thank you all for your contribution!

Regards

1 Like

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