I am currently working on a project (web app) at university to be able to calculate the amount of time spent during night flying. Currently, I have,
Departure Lat and Long and Departure Time in UTC
Arrival Lat and Long and Arrival Time in UTC Sunset and
Sunrise Times (Based on dates) for both Arrival and Departure airfields in UTC

An example:
Depart UK Edingburgh airport on the 23 April 2019 at 11:10 UTC
Arrive Riyadh Airport at 18:10 UTC Total Time 7hr
day flight = ?
night flight = ?

I know many places online do this type of calculation for you, so I am wondering if there is a formula or method available that allows me to do this calculation (Which I can then convert to code)?


  • $\begingroup$ Hello, @Bianfable, this isnt quite what I was looking of, am looking for a more mathematic calculation, but thank you $\endgroup$
    – pilotman
    Oct 28 '20 at 12:58
  • 1
    $\begingroup$ If you are more interested in the maths rather than the aviation aspect, you might get a better answer at Geographic Information Systems. $\endgroup$
    – Bianfable
    Oct 28 '20 at 13:07
  • 2
    $\begingroup$ Before you can get to the math, you need to figure out what “night” means. Every country has their own definition, and some have more than one. And they’re all different. It is entirely possible that a flight changes from day to night or vice versa simply because you crossed a border. $\endgroup$
    – StephenS
    Oct 28 '20 at 14:26
  • $\begingroup$ For that, I will base it on EASA guidance but for now, for simplicity, I will just assume between sunset and sunrise $\endgroup$
    – pilotman
    Oct 28 '20 at 15:10
  • $\begingroup$ Welcome to aviation.SE! I suggest you check out this article on how it's implemented in a popular online logbook. The code is also on github. $\endgroup$
    – Pondlife
    Oct 28 '20 at 15:34

This answer will address your question according to US FAA guidelines. Make sure to verify with your country’s aviation agency.

Civil Twlight

The time that you can log as “night” is based on the start or end of “civil twilight.” Civil twilight is defined as the time when the geometric center of the Sun’s disk is at most 6 degrees below the horizon. Civil twilight, as a general rule, is usually the 30 minutes before sunrise or after sunset. However, that can vary quite a bit with your location on the Earth’s surface.

Logged Time

Before (morning) or after (evening) civil twilight and between the two is when you can log night flight. You can take your total time (ie 2.3 Hobbs) and subtract any time that would not count as night and the result is what you are legally allowed to log as night time (at least here in the US).

Application for Development

I understand you're problem as a developer - you will have to use a website like timeanddate.com to grab an API that can find a local civil twlight using a city as an input. You will have to write a function that takes the departure time and determines whether it counts as night time, and then subtract any flight time that is ineligible.

I hope this addressed the mathematical request of your question and let me know if I can clarify at all.

  • $\begingroup$ That great thanks, But referring to the example above, say we depart in the day and are flying W->E, then at what point during that flight would we hit night? $\endgroup$
    – pilotman
    Oct 28 '20 at 13:39
  • $\begingroup$ I would clarify by saying that when the time in whatever local time zone you are in is classified as night by the criteria above, you can determine that your flight is now flying under “night” logging. $\endgroup$ Oct 28 '20 at 13:42
  • 1
    $\begingroup$ @AkshayPatel Night time is not based on departure time or arrival time, it is calculated on the basis of what portion of the flight was flown at a time within civil twilight time for a particular location. Depending on what type of aircraft you are flying, it is possible to fly nonstop for 24 hours and not be able to log night time. $\endgroup$ Oct 28 '20 at 16:50
  • $\begingroup$ @JuanJimenez , this I understand and that is why I am trying to calculate at what point of flight would hit defined night (If traveling East to West and you take off in the day) you may eventually catch the night (Assuming constant speed) (If that makes sense?) $\endgroup$
    – pilotman
    Oct 28 '20 at 17:00
  • $\begingroup$ The answer to your question depends on many factors that you have not expressed, such as speed, time of departure, flight route, etc. To my mind, as a programmer, it would make more sense to sample the location of the aircraft and local time at defined intervals to decide if the flight is currently within local civil twilight time at that location. $\endgroup$ Oct 29 '20 at 2:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.