title: PHP Mysql Calculating total flight hours per day from just two datetimes across day
body: <pre><code>Row_id Sensor_ID  datetime_takeoff       datetime_landing
  1      SFO        2013-09-18 04:34:22    2013-09-19 08:34:22
  2      BWI        2013-09-18 04:34:22    2013-09-18 16:55:23 
  3      BWI        2013-09-18 20:34:22    2013-09-19 10:34:22   
  4      SFO        2013-09-19 15:21:22    2013-09-19 20:34:22   
  5      BWI        2013-09-19 20:34:22    2013-09-20 06:15:16   
  6      SFO        2013-09-19 23:47:22    2013-09-20 07:59:59   
  7      BWI        2013-09-20 11:34:05    2013-09-21 02:05:21   
  8      SFO        2013-09-20 10:28:56    NULL   
  9      BWI        2013-09-21 04:09:57    NULL         
  </code></pre>
  
  <p><strong>This is for PHP and Mysql</strong><br>These are airplane takeoff and landing datetime's for two planes SFO and BWI. I'm trying to calculate how many hours per day each plane is in the air. Flight duration is easy just DATETIMEDIFF but hours per day in the air is proving difficult.</p>
  
  <p><strong>I figure I can break it down into 2 steps:</strong>
  <br>1. For any take off and landing pair in the same day just get the datetimediff and if <strong>datetime_takeoff</strong> and <strong>datetime_landing</strong> are not in the same day then insert the total amount of hours from mindnight. I can run this as it occurs.</p>
  
  <p><br><br>2. Run a check every day at midnight and check if the datetime_landing is NULL and IF the datetime_takeoff is TODAY, THEN calculate the hours to midnight. IF datetime_takeoff is not today then insert a value of 24hrs. I figure this will cover timedate_landings that are not on the same day/NULL<br><br></p>
  
  <p>Does this logic make sense where all the data will be processed?</p>