title: Reusable function for getting mysql data
body: <p>I want to write a function which is able to return the sum of the <code>total_excl</code> column at the MySQL database. I’ve written a function, but its not reusable. </p>
  
  <p>The function for the first quarter of the year.</p>
  
  <pre><code>public static function getFirstQuarterTotalExcl(){
      $first_day_of_1_quarter = date('Y-01-01');
      $last_day_of_1_quarter = date('Y-03-31');
      $query = "SELECT SUM(total_excl) FROM ".Zim_Properties::getTableName('Invoice')." WHERE invoice_date BETWEEN '$first_day_of_1_quarter' AND '$last_day_of_1_quarter'";
      $total = Zend_Registry::get('db')-&gt;fetchAll($query);
      return round($total[0]["SUM(total_excl)"]);
  }
  </code></pre>
  
  <p>The second function for the second quarter of the year:</p>
  
  <pre><code>public static function getSecondQuarterTotalExcl(){
      $first_day_of_2_quarter = date('Y-04-01');
      $last_day_of_2_quarter = date('Y-06-30');
      $query = "SELECT SUM(total_excl) FROM ".Zim_Properties::getTableName('Invoice')." WHERE invoice_date BETWEEN '$first_day_of_2_quarter' AND '$last_day_of_2_quarter'";
      $total = Zend_Registry::get('db')-&gt;fetchAll($query);
      return round($total[0]["SUM(total_excl)"]);
  }
  </code></pre>
  
  <p>As you can see. This code isn’t reusable which means that for every quarter of the year I have to write a new function. I want to make one function for every quarter. What should I do to make it reusable?</p>