Comparing time and checking if its greater than 2 hours - date time activity

Hello All,

I have the time 9/11/2024 7:12:17 PM (mm/dd/yyyy hh:mm:ss tt format -12 hours format)

I want to compare the current time to the above time and return true if the gap between the current time and the above time is greater than 2 hours.

Thank you

Try the below steps:

  1. Parse the given time using DateTime.ParseExact with the format “M/d/yyyy h:mm:ss tt”.
  2. Get the current time with DateTime.Now.
  3. Subtract the given time from the current time using Subtract to get a TimeSpan.
  4. Check if timeDifference.TotalHours > 2 to determine if the gap is greater than 2 hours.

try below approach

givenDate = DateTime.ParseExact(“9/11/2024 7:12:17 PM”, “M/d/yyyy h:mm:ss tt”, System.Globalization.CultureInfo.InvariantCulture)

currentDate = DateTime.Now

timeDifference = (currentDate - givenDate).TotalHours

Hi @Hansen_Clyde_Lobo

Use multiple assign activity to calculate it

  • inputTime = DateTime.ParseExact(“9/11/2024 7:12:17 PM”, “M/d/yyyy h:mm:ss tt”, System.Globalization.CultureInfo.InvariantCulture)
  • currentTime = Now
  • timeDifference = currentTime - inputTime
  • isGreaterThan2Hours = timeDifference.TotalHours > 2

in writeline print

  • isGreaterThan2Hours.ToString

Hi @Hansen_Clyde_Lobo

Please find my solution
TimeDifference.zip (1.7 KB)

1 Like

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