Subtract two date columns and find differnece

Hi,
i want to find difference bw two dates from two columns which From Date and To Date.
In for each row i tried ,

col1 = Convert.ToDateTime(row(“From Date”).ToString)
col2 = Convert.ToDateTime(row(“To Date”).ToString)
dt.Rows(index).Item(“Difference_Column”)= (col2.Subtract(col1)).ToString(“dd”)

the above condition works well, but if “From date and To date” are same it returns “0” but the expected output should be “1”. How to achieve this

@Muthulakshmi_Thangamuthu

As you are subtracting the date so if it is same date then it will result to zero.

To make it 1 make a if condition that (col2.Subtract(col1)).ToString = “0”

Then
dt.Rows(index).Item(“Difference_Column”)= “1”

Else
dt.Rows(index).Item(“Difference_Column”)= (col2.Subtract(col1)).ToString(“dd”)

Hope this may help you

Thanks

hi @Srini84 thanks for the suggestion.

Here i would like to add (+1) day for all the result not only for “0”.
I tried using Adddays(+1) but nothing works.

Hi @Muthulakshmi_Thangamuthu

Make the little modifications as below

(col2.Subtract(col1)).AddDays(1).ToString(“dd”)

Regards

Nived N :robot:

Happy Automation :relaxed::relaxed:

Hi i tried it but it shows error.

Hi @Muthulakshmi_Thangamuthu

Try this
((b-a).Days+1).ToString

Regards,

Nived N
Happy Automation

Thanks @NIVED_NAMBIAR

But no luck its throwing “Assign: Exception has been thrown by the target of an invocation”. run time error

hi @Muthulakshmi_Thangamuthu

where are u getting the data ?

means the datetime?

Yes its date time.

Test.xlsx (7.9 KB)
DatediffSum.xaml (9.7 KB)

this is the sample flow

Hi @Muthulakshmi_Thangamuthu

Is there any column name Status in the excel file?

I think that was issue

i added a status in the excel and run your workflow

it work fine

Test.xlsx (8.6 KB)

DatediffSum.xaml (9.7 KB)

Regards,

Nived N

Happy Automation

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