Thank you for the informative reply with code.
Now, lets say I have 8000 records in my table- will this loop kill performance? I was hoping for an SQL solution to avoid the linear search. I mean, I know best case or optimistic case is that you find the previous and next before hitting the end of the loop. But there is always the possibility you have to traverse the entire result set.
I was trying to do something like this:
SELECT a.id FROM tablename a, tablename b
WHERE b.id = 25 AND a.wo_comp_date <= b.wo_comp_date
ORDER BY wo_comp_date LIMIT 2;
I'm beginning to see that the linear approach might be my only option! Thanks again!
EDIT: Actually I can think of ways to cut down on the set a little bit. For instance, only query the current and sequential date (to handle the borderline case)- that will reduce my result set size by a lot, and then I can linear search that.