title: PHP/MySQL Timezone Clarification
body: <p>I'm currently having an issue wrapping my brain around the notion of converting my MySQL time to a specific timezone, depending on the user's settings.</p>
  
  <p>All of my MySQL times are stored in UTC time, in the following format: </p>
  
  <p><code>2009-11-08 17:06:40</code>  </p>
  
  <p>Once I query the time, I'm not quite sure how to convert it to the appropriate timezone using PHP.</p>
  
  <p>Thus, in the example above, I'd like to display:</p>
  
  <p><code>2009-11-08 09:06:40</code></p>
  
  <p>Here's what I currently have (which probably needs to be fixed):</p>
  
  <pre><code>$sql = 'SELECT date FROM mytable';
      require("connection.php");
      $result = mysql_db_query($DBname,$sql,$link); 
      while($row = mysql_fetch_assoc($result)) { 
  
      $dt_obj = new DateTime($row['date']); 
      $dt_obj-&gt;setTimezone(new DateTimeZone('PST')); 
      echo $dt_obj;       
      echo "&lt;br&gt;";
       }
  </code></pre>
  
  <p>First off, I get the following error: </p>
  
  <p><code>Catchable fatal error: Object of class DateTime could not be converted to string</code></p>
  
  <p>Secondly, I am confused as to whethere I'm setting it up properly to display the time in the correct timezone anyway (in this case, PST).</p>
  
  <p>Any suggestions on how to do this would be greatly appreciated.  Thanks!</p>
  
  <p><b>UPDATE:</b></p>
  
  <p>I took GZipp's advice, and modified the code to look like:</p>
  
  <pre><code>$dt_obj-&gt;setTimezone(new DateTimeZone('America/Los_Angeles')); 
  echo $dt_obj-&gt;format('Y-m-d H:i:s');
  </code></pre>
  
  <p>However, it's displaying my time (using the example from above) as:</p>
  
  <p><code>2009-11-08 15:06:40</code></p>
  
  <p>Any ideas on what would be causing this?</p>