Compare two mail dates (mail.headers("date")) and check the time difference is less than 2 hours


I am comparing two mail date values.
I want to check if the difference in time is less than 2 hours.
Can someone help me here ?

Sindhuja R

Make sure that datevalues are type of DateTime.

int hours = (datevalue1 - datevalue2).TotalHours


Yes, I have them as DateTime variables but the error is .ToHours is not a member of system.timespan.
What can be done to resolve this ?


Can you provide your datetime values.

I am reading the date value from outlook (mail.headers(“Date”)) mails and compare with current system date.
Var1 value : 03/19/2019 05:05:03 and Var2 value : Both are DateTime variables. I want to compare and check if the time difference is less than 2 hours.

Hi @Sindhuja252

Refer the below workflow

Testing.xaml (10.1 KB)

The one which karthik has mentioned also works for me, i think you have used ToHours its TotalHours

(Datetimenow-Datetime1).TotalHours and the return type is double


Thanks for all your help.!
This xaml gives me the time difference. But i want to check if it is less than 2 hours.
I have assigned it to a generic variable (Timedifference = DiffHours.TotalHours.ToString) and set the condition as Timedifference < 2. here the value of time difference is 5.33XXX
I am not getting the expected output.It is flowing to False branch.
Please help.

Hi @Sindhuja252

So the timedifference between mail received and the current time is 5.33 hours

When you use if condtion and perform 5.33<2, because the difference is not less than 2 , it will go to false branch.

So i have hardcoded the value for Datetime1 variable, can you use some recent mail received time and check

Sorry, that’s a confusion from my end.

Thanks Anil and Karthik.
I got the expected result.

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