Getting flight arrival time

Hi, based on the airport ICAO and flight number I want to get the ETA for a flight that is in transit (in air)

I’m trying with the FlightInfo method, however, the method does not always return the next flight that will arrive at the airport, so I’m forced to get 5 total flights and analyze each one, by departure / ETA, which one is the next one to arrive at the airport.

This seems extremely overcomplicated… is there a simpler way? I just want to get the ETA.

FlightInfoStruct fi = client.FlightInfo(flight, 5);

foreach (FlightStruct x in fi.flights) {
    DateTime filed_departuretime = UnixTimeStampToDateTime(x.filed_departuretime);

    if (x.origin == "TJSJ" && filed_departuretime > DatePickupActual) {
        TimeSpan timeDifference = filed_departuretime.Subtract(DatePickupActual);

        // if the difference is bigger than 4 hours (240 minutes) that 
        // means it's another day flight, so skip onto the next record
        if (timeDifference.TotalMinutes < 240) {
            // some code here...
            break;
        }
    }
}

The records returned are in order of decreasing timestamp (starting furthest in the future and advancing backwards in time). Depending on how many future flights we currently have flight plans/schedules for, you may need to request more than 5 flights.

To find the flight that is currently in flight, look for records that have actualdeparturetime != 0 and actualarrivaltime == 0.

I recommend using FlightInfoEx rather than FlightInfo for newly developed applications.

Thank you for the tip bovineone, it helped in cleaning up the code.

I’m still facing problems getting the ETA, for example: on your website, today JBU1589 flight shows an ETA of 10:24AM, but when querying the API I can’t find “10:24AM” anywhere. Please take a look at the FA page screenshot and also the VS debug window, showing the FlightInfoEx for that same flight, and none of the values is 10:24AM.

FA JBU1589 screenshot

FA JBU1589 Visual Studio Debug Window

Can you please tell me what I’m doing wrong? Also, how do you calculate “49 minutes late”? using which fields?

Thank you and sorry for so many questions, I’m honestly finding this API hard to understand / use.

Some of your questions may have already been answered in the FAQ: https://flightaware.com/commercial/aeroapi/faq.rvt#findstatus