title: Redshift: Date Comparisons for a Javascript time format Varchar field
body: <p>I'm new to Redshift and am trying to write a query which will return records where a field contains a date value within the last 30 days.</p>
  
  <p>This works:</p>
  
  <pre><code>SELECT * FROM my_table WHERE deactivated &lt; GETDATE() LIMIT 10;
  </code></pre>
  
  <p>I get 10 rows returned, all in the past. The field <code>deactivated</code> is stored as varchar(32) containing JavaScript format timestamps, e.g. <code>2018-06-27T14:30:18.2457388Z</code>.</p>
  
  <p>However, this doesn't work:</p>
  
  <pre><code>SELECT * FROM my_table WHERE deactivated &gt;= DATEADD(day, -30, GETDATE());
  </code></pre>
  
  <p>I have looked at <a href="https://stackoverflow.com/questions/41662911/what-is-the-application-of-date-in-redshift" title="related question">this question</a> but it doesn't really help with the above. What's the best way to query between dates stored in this format?</p>
  
  <p>Thanks.</p>