title: Postgres Time Difference
body: <p>I am trying to retrieve time difference in minutes from a table(login_history as t1) using postgresql .</p>
  
  <p>When i tried this code </p>
  
  <pre><code>((date_part('hour', timestamp '2014-04-25 09:44:21')- date_part('hour', timestamp '2014-04-25 08:32:21'))*60 +(date_part('minutes', timestamp '2014-04-25 09:44:21')- date_part('minutes', timestamp '2014-04-25 08:32:21'))) as TimeNew
  </code></pre>
  
  <p>It works fine.
  But when i tried to retrieve information from a table t1 using this code</p>
  
  <pre><code>((date_part('hour', timestamp t1.login_date)- date_part('hour', timestamp t1.logout_date))*60 +
  (date_part('minutes', timestamp t1.login_date)- date_part('minutes', timestamp t1.logout_date))
  ) as TimeNew
  </code></pre>
  
  <p>It throws this error</p>
  
  <pre><code>SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "t1"
  </code></pre>
  
  <p>Thanks</p>