How to get timezone from airport code (IATA/FAA)

You are confusing a "time zone" with a "time zone offset". They are not the same thing. You can't just ask for the offset at a location - you also would need to know the specific time in question. It's invalid to ask "What's the time zone offset for LAX" - because in the winter it will be -8 while in the summer it will be -7.

You can ask "what is the offset at this location right now", but that might give you a different answer depending on when you ask. So the date and time have to be part of the input.

What you really need to know instead is that LAX corresponds to the IANA time zone of America/Los_Angeles. These time zone codes are understood by the PHP date/time API, and many other systems. (.NET Windows users can convert these to Microsoft Windows time zones using my TimeZoneConverter library.)

To do this, you need to take the latitude and longitude of each airport (which are available from OpenFlights and many other places), and use one of the methods described here to lookup the IANA time zone for those coordinates.

I've already written code for this in C#, which you can find here. The output is included in a .csv file, which you can parse and use in any language you like. It includes both IANA and Microsoft time zones.

Be sure to also read the timezone tag wiki, especially the parts on the IANA database, and the section titled "Time Zone != Offset".

Also note that while the lat/lon coordinates in the OpenFlights database are great, the time zone data in that file is not very accurate, so going through the process I described is important. When it comes to the specifics of time zones, you should only trust the IANA database and make sure you keep updated.


Seeing as the question is still open I'd like to point to my very own timezone map files. For your particular purpose, the IATA tzmap seems perfect:

https://raw.github.com/hroptatyr/dateutils/tzmaps/iata.tzmap

Obviously, you'd have to snarf the offset in question (it depends on a date as it might change over time) from the zoneinfo files, e.g. with zdump(1).

Tags:

Php

Timezone