title: Handling mySQL date formats when local date format is different
body: <p><strong>Scenario:</strong> My PHP application will always use the date field DD-MM-YYYY. MySQL obviously always stores dates in YYYY-MM-DD</p>
  
  <p><strong>Disclaimer:</strong> I know how to manually change the date formats - that is not the question</p>
  
  <p><strong>Question:</strong> What is a good, clean, elegant way to ensure that my application <strong><em>always</em></strong> retrives the date in DD-MM-YYYY, and mySQL <strong><em>always</em></strong> receives the date in YYYY-MM-DD to be stored.</p>
  
  <p>i.e. Basically I want to have a single place where the conversion occurs <strong><em>automatically</em></strong>, without me having to call it each and every time I do an SQL query. That way it doesnt matter if I "forget" to do a date_conversion - it will just always happen each and every time....</p>
  
  <p>I'm thinking of some sort of callback somewhere?</p>
  
  <p><strong>(edit) My idea:</strong> I currently use the Codeigniter framework. I'm thinking of using MY_Model, using before_get, before_insert and before_update callbacks. In these callbacks, I can go through all the fields using something like this for a SELECT:</p>
  
  <pre><code>// {insert my query here to get records from DB. Then:
  $query = $this-&gt;db-&gt;query();
  $fields = $query-&gt;field_data(); 
  foreach ($fields as $field)
  {
        if ($field-&gt;type == 'date')
             // do conversion here
  }
  </code></pre>
  
  <p>and do something similar for an UPDATE/INSERT callback. From what I can tell, there is no extra work on the database (because Codeigniter supplies the information in the $query result)</p>
  
  <p>Thoughts?</p>
  
  <p><strong>edit 2:</strong> other idea: just do this for each model, and define which fields are date fields, and just apply the change at each callback... yeah... might do that...?</p>