Im trying to get the closest date to today from array “dates”.
Example: Today is 2011-09-10 -> next closest date from JSON file is “2012-12-20” -> $(‘div’).append(‘date1: ‘ + dates.date1);
Example 2: Today is 2012-12-21 -> next closest date from JSON file is “2012-12-25” -> $(‘div’).append(‘date2: ‘ + dates.date2);
Tried a few solutons, but without success. Need help! Here is JSON file.
[
{
"fields": {
"field1": "Field1",
"field2": "Field2"
},
"dates": {
"date1": "2012-12-20",
"date2": "2012-12-25",
"date3": "2012-12-31"
}
}
]
Whoever it was that had a solution like this…. put it back please 🙂
all it needed was a sort algorithm
Edit
Just read the question more closely… you don’t want any dates previous too current date to be considered even if it is closer… this is not to hard either: