title: PHP: Timezone adjustment function calculates Y-m-d H:i:s differently than Y-m-d
body: <p>I have a custom-written PHP function which turns the passed passed value to the user's timezone (the <code>getSystem('timezone')</code> line).  Here is the function:</p>
  
  <pre><code>function dateAdjusted($format = 'Y-m-d H:i:s', $when = null) {
  
      if(is_int($when)) $when = date($format, $when); // already in epoch, change to string
      else $when = date($format, strtotime($when));
      $utc_date = DateTime::createFromFormat($format, $when, new DateTimeZone('UTC'));
      $local_date = $utc_date;
  
      $zone = getSystem('timezone');
      $zone_obj = new DateTimeZone($zone);
      $local_date-&gt;setTimeZone($zone_obj);
  
      $result = $local_date-&gt;format($format);
      return $result;
  }
  </code></pre>
  
  <p>Notice that it always translates from UTC, since that's what we store in the database.  On a system where the timezone is set to <code>America/New_York</code> I get a weird bug:</p>
  
  <p><code>echo dateAdjusted('Y-m-d H:i:s', strtotime('2015-07-28 00:00:00')); // 2015-07-27 20:00:00</code>
  <code>echo dateAdjusted('Y-m-d', strtotime('2015-07-28 00:00:00')); // 2015-07-28</code></p>
  
  <p>All I did is remove the <code>H:i:s</code> and it stops calculating over the day... what am I missing?</p>