I am getting a response from my api where start_date is given. I want to extract the id from json whose next date time is closest to current date time.
[
{
"expected": {
"id": 1,
"end_time": "2021-10-01T06:35:00.659Z",
"start_time": "2021-10-01T06:35:00.659Z"
}
},
{
"expected": {
"id": 2,
"end_time": "2021-09-30T17:08:29.307Z",
"start_time": "2021-09-30T17:08:29.307Z"
}
},
{
"expected": {
"id": 3,
"end_time": "2021-10-01T09:49:18.574Z",
"start_time": "2021-10-01T09:49:18.574Z"
}
},
{
"expected": {
"id": 4,
"end_time": "2021-09-30T17:08:29.303Z",
"start_time": "2021-09-30T15:08:29.303Z"
}
},
]
As you can see based on date id:2 and id:4 has the closest start_date from current date, and then based on time id:4 is the closest.
I am not able to figure out how to extract this id. I have been trying for hours but not getting anywhere close to the solution. Please help.