title: How does JDBC/Postgres compare a timezone-less java.util.Date with a Timestamp?
body: <p>We have a <a href="https://en.wikipedia.org/wiki/PostgreSQL" rel="nofollow noreferrer">Postgres</a> table that has two <a href="https://www.postgresql.org/docs/current/datatype-datetime.html" rel="nofollow noreferrer"><code>TIMESTAMP WITHOUT TIME ZONE</code></a> columns, prc_sta_dt and prc_end_dt. We check to see whether a <code>java.util.Date</code> falls in between the start and end dates.</p>
  
  <p>Here is some of the Java code, which is simplified but gets the point across.</p>
  
  <pre><code>// This format expects a String such as 2018-12-03T10:00:00
  // With a date and a time, but no time zone
  
  String timestamp = "2018-12-03T10:00:00";
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
  Date searchDate = formatter.parse(timestamp);
  
  // Here's the Postgres query
  
  String query = "select promotion_cd from promotions " + 
                 "where prc_sta_dt &lt;= :srch_dt and prc_end_dt &gt;= :srch_dt";
  
  Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
  map.put("srch_dt", searchDate);
  
  List&lt;Promotion&gt; promotions = jdbcTemplate.query(query, map, promotionMapper);
  </code></pre>
  
  <p>In our Postgres table, we have promotions that start at 9am on 12/3/2018 and end at 3pm on the same day. The prc_sta_dt and prc_end_dt colums in our database for these rows are <code>2018-12-03 09:00:00.0</code> and <code>2018-12-03 15:00:00.0</code></p>
  
  <p><strong>Question:</strong> When <a href="https://en.wikipedia.org/wiki/Java_Database_Connectivity" rel="nofollow noreferrer">JDBC</a>/Postgres accepts our <code>searchDate</code> and compares it to these timestamps, will it accept the given search date of 10am (2018-12-03T10:00:00) or will it treat this time as being under the time zone that the server is running on, and then convert that to UTC?</p>
  
  <p>For example, if the server is running in Chicago, then will it interpret 10 am as 10am CST and then convert that to 4pm UTC before doing the comparison in the database? If so then we're out of luck!</p>
  
  <p>I doubt this would happen, but I just want to make sure so there are no surprises.</p>