title: How to subtract two dates (from 2 columns in database) in Codeigniter
body: <p>I have to make in my model a query to order by this subtraction between two dates. 
  I have to calculate subtraction between columns <code>ordersheader.transportDate</code> and <code>orderitems.forecast_hour</code>. These are in 2 tables - <code>ordersheader</code> and <code>orderitems</code>. I've joined them ON <code>idOrder</code>.<br>
  First, I have to find max(<code>orderitems.forecast_hour</code>) for each idOrder and then to subtract <code>ordersheader.transportDate</code> - this max value from <code>orderitems.forecast_hour</code> for each idOrder. It should be calculated in hours because it's the same date.
  It should be displayed first, these idOrders which <code>orderitems.transportDate</code> - this max <code>orderitems.forecast_hour</code> &lt; 0. 
  I tried with this but it gave me error:</p>
  
  <pre><code>Call to undefined function DATEDIFF
  </code></pre>
  
  <p>Ho to do that?</p>
  
  <pre><code>&lt;?php
   function getOrders(){
              $date = new DateTime("now");
              $curr_date = $date-&gt;format('Y-m-d');
              $this-&gt;db-&gt;select('orderitems.eggSize as size');
              $this-&gt;db-&gt;select('ordersheader.*,customer.name,GROUP_CONCAT(orderitems.itemNumber) as itemNumber');
              $this-&gt;db-&gt;select('ordersheader.*,customer.name,ordersheader.*,customer.name,GROUP_CONCAT(orderitems.quantity ) as quantity ');
              $this-&gt;db-&gt;select('ordersheader.*,customer.name,ordersheader.*,customer.name,GROUP_CONCAT(orderitems.unitPrice) as unitPrice');
              $this-&gt;db-&gt;select('ordersheader.*,customer.name,ordersheader.*,customer.name,GROUP_CONCAT(orderitems.eggSize ) as eggSize');
              $this-&gt;db-&gt;select('GROUP_CONCAT(orderitems.forecast_hour) as forecast_hour');
              $this-&gt;db-&gt;from('ordersheader'); 
              $this-&gt;db-&gt;join('orderitems', 'orderitems.idOrder = ordersheader.idOrder');
              $this-&gt;db-&gt;join('customer', 'customer.idCustomer = ordersheader.idCustomer');
              $this-&gt;db-&gt;where('DATE(orderDueDate)', $curr_date);
              $this-&gt;db-&gt;group_by('orderitems.idOrder');
              $this-&gt;db-&gt;order_by(DATEDIFF('hour', 'ordersheader.transportDate', 'orderitems.forecast_hour'));
              $query = $this-&gt;db-&gt;get();
              return $query-&gt;result();
          }
  </code></pre>