title: Converting Between Timezones in Postgres
body: <p>I am trying to understand the timestamps and timezones in Postgre. I think I got it, until I red <a href="http://phili.pe/posts/timestamps-and-time-zones-in-postgresql/" rel="noreferrer">this</a> article. <br> Focus on the "Converting Between Timezones" part. It has two examples. </p>
  
  <p>(Consider the default timezone configuration to be UTC.)</p>
  
  <p>Example 1</p>
  
  <pre><code>db=# SELECT timezone('US/Pacific', '2016-01-01 00:00'); outputs 2015-12-31 16:00:00
  </code></pre>
  
  <p>According to the article and what I understand, because the <code>'2016-01-01 00:00'</code> part of the <code>timezone</code> function is just a string, it is silently converted to the default UTC. So from <code>'2016-01-01 00:00' UTC</code> it is then converted to <code>US/Pacific</code> as asked by the <code>timezone</code> function, that is <code>2015-12-31 16:00:00</code>.  </p>
  
  <p>Example 2 </p>
  
  <pre><code>db=# SELECT timezone('US/Pacific', '2016-01-01 00:00'::timestamp); outputs 2016-01-01 08:00:00+00
  </code></pre>
  
  <p>Excuse me, I dont see why and the explanation there does not help. Ok, the <code>'2016-01-01 00:00'::timestamp</code> part of the <code>timezone</code> function is no longer a string, but an actual timestamp. In what timezone? If it is UTC, the output would have to be the same as the Example 1. So it is automatically converted to <code>US/Pacific</code>? Then the output is in UTC? But why? I asked for a <code>US/Pacific</code> in my <code>timezone</code>  not a UTC.</p>
  
  <p>Please explain how the <code>timezone</code> behaves when gets a timestamp and gets asked to transform it. Thank you.</p>