You can create a function that returns the difference between two dates, run all the possible dates through this function, then pick the lowest difference.
Something like this (pseudo c code)
int array[numdates];
for (int i=0;i<numdates;i++)
array[i]=compareDates(date[index], currentDate);
Then you can sort the array so the lowest number is at the beginning (or end) and return that one.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…