The straightforward way:
Loop over the list and at each iteration calculate the difference using millisecondsBetween($IteratorYourObjects, $currentDateTime)
The probably more efficient way:
- retrieve the list, with ‘Range: first’, xpath ‘Time’ < currentDateTime and sorting on Time descending.
- retrieve the list, with ‘Range: first’, xpath ‘Time’ > currentDateTime and sorting on Time ascending.
- using millisecondsBetween to calculate which of the two is closest to currentDateTime.
You can do it faster with an Xpath. Just retrieve the first object where the datetime field is < then the current date time with a descending sort on that same datetime field. The record you retrieve is the one.