How to find nearest time in the list/table for the specific time given

Hello Everyone,
I have a situation where I have multiple time values in the list/table for example (12:35 AM,11:36 AM,10:15 AM) and I have another time present i.e. 11:55 AM now I need to select the time which is nearest to the given time from the list or table.

any help would me much appreciated.

Hi @Govind_Singh

Please refer below video for list

In your case you have to create list of timespan Instead of datetime

Hello Manoj,
Thank you for the reference video and it gave me some idea however i have a different scenario
i have a table 2 column like
Time City
10:15 AM A
10:45 AM B
11:12 AM C
11:30 AM D

Now i need to find the time which is nearst to 10:25 AM and on the basis of that i need to extract the city name.

Some introduction basics:



Modified Testdata:

Lets assume similar to the test data following

Compare Value: 10:25 AM
10:25 AM - 10:15 AM = -10 min
10:25 AM - 10:30 AM = 5 min

With a simple orderBy it would take -10 as closest, but +5 (10:30) is more close to 25
Thats the reason we worked with Math.Abs(…
Instead of Ticks we can also use a highler level unit e.g. Seconds. This just depends on your needed precission.

Find starter help here:
GetClosestTimeSpan_AMPM.xaml (7.4 KB)

Hi @Govind_Singh ,

You can also refer below test file.

Test.xaml (8.5 KB)