title: How to compare dates with psycopg2 (PostgreSQL)?
body: <p>By using the PostgreSQL Python module psycopg2, I want to find rows that have an end time that falls before some timestamp. I tried to do this with a <code>cursor.execute(…)</code> on a SQL query with <code>… where end_time &lt; %s</code>, where %s replaced by a <code>datetime.datetime</code> object with a timezone. The SQL generated by psycopg2 is:</p>
  
  <pre><code>select * from my_table where end_time &lt; '2014-05-01T13:00:00+00:00'::timestamptz;
  </code></pre>
  
  <p>which returns a row like:</p>
  
  <pre><code>id  |     start_time      |      end_time       
  331 | 2014-05-01 14:55:00 | 2014-05-01 15:05:00
  </code></pre>
  
  <p>The end time is not earlier than 2014-05-01 at 13:00 UTC, contrary to what I was expecting.</p>
  
  <p>What is the proper way of performing the desired time selection in psycopg2?</p>