in reply to choosing closest date to a given date

If you have only one specified date, or do that only once in a while, then the easiest is to traverse your array of dates and find the smallest time difference.

If, on the other hand, you need to do that with large loads of specified dates, then it might be worth to sort your date array once and then implement a binary search algorithm.

  • Comment on Re: choosing closest date to a given date