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.
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.
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.