title: PostgreSQL get time difference between timestamps
body: <p>I've looked at many SO questions related to this but I can't seem to get anything to work. I'm not very good with semi complex SQL queries. </p>
  
  <p>I want to get the difference between the current time and a column that is in unix timestamp in hours.</p>
  
  <p>I'm not sure what I'm doing wrong or right for that matter. The goal is to only pull the rows that is less than 24 hours old. If there is a better way or example that <strong>works</strong> that would be great. </p>
  
  <p>I tried several answers from here <a href="https://stackoverflow.com/questions/1964544/timestamp-difference-in-hours-for-postgresql">Timestamp Difference In Hours for PostgreSQL</a></p>
  
  <p>I can't get this query to work no matter how many different ways I try it. <code>wc.posted</code> is a <code>bigint</code> store as <code>unix timestamp</code></p>
  
  <pre><code>SELECT w.wal_id, wc.com_id, w.posted AS post_time, wc.posted AS com_time 
  FROM wall as w LEFT JOIN wall_comments as wc ON w.wal_id=wc.wal_id 
  WHERE (EXTRACT(EPOCH FROM wc.posted)) &gt; current_timestamp - interval '24 hours'
  </code></pre>
  
  <p>Then the <strong>Error:</strong></p>
  
  <pre><code>ERROR:  function pg_catalog.date_part(unknown, bigint) does not exist
  LINE 1: ... wall_comments as wc ON w.wal_id=wc.wal_id WHERE (EXTRACT(EP...
                                                               ^
  HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
  
  ********** Error **********
  
  ERROR: function pg_catalog.date_part(unknown, bigint) does not exist
  SQL state: 42883
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Character: 148
  </code></pre>
  
  <p>Here is a simplified <a href="http://sqlfiddle.com/#!1/8a68a/3" rel="nofollow noreferrer">fiddle</a></p>