Time difference in 24 hours format

Hi Team i have two strings coming in for example A=“2315”, (as in 23:15) B=“0115” as in (01:15) i need to get the time difference between it and it should be 2. Please let me know how we can achieve this in Ui path.

Hi @Ajith209

How about the following?

Int32.Parse(DateTime.ParseExact("2315", "HHmm", System.Globalization.CultureInfo.InvariantCulture).Subtract(DateTime.ParseExact("0115", "HHmm", System.Globalization.CultureInfo.InvariantCulture)).TotalHours.ToString)

The difference comes as 22. That is the issue.





How should the output be, in your opinion?


22 is not the expected answer it should be two. as the time difference is only two


How about this

(Math.Abs((DateTime.ParseExact("0115", "HHmm", System.Globalization.CultureInfo.InvariantCulture).AddDays(1) - DateTime.ParseExact("2315", "HHmm", System.Globalization.CultureInfo.InvariantCulture)).TotalHours) Mod 24).ToString()

This works. Thanks a lot for your help.

Hi But the same is not working if the string is A=2015 and B=2315. it can also happen like that. Here the time difference should be 3 as well. any idea how to achieve both?

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