title: Python: Embed 'Start_date' & 'End_date' as variables under SQL within Python Script
body: <p>I am using Python to connect to Amazon Redshift to pull data, the following part is to execute the SQL part. ('engine' and related libraries are already defined)</p>
  <pre><code>try_data = pd.read_sql_query(text(try_sql), engine)
  
  try_data.head(3)
  </code></pre>
  <p>It works fine if 'start_date' and 'end_date' is hard coded under SQL query like:</p>
  <pre><code>try_sql = &quot;&quot;&quot;
  select * from users where created_at &gt;= '2019-07-01' and created_at &lt; '2021-07-01' limit 10
  ;
  &quot;&quot;&quot;
  
  </code></pre>
  <p>But fails if I try to define <code>start_date</code> and <code>end_date</code> as variables and then put it into the query:</p>
  <pre><code>start_date = '2019-07-01'
  end_date = '2021-07-01'
  </code></pre>
  <pre><code>try_sql = &quot;&quot;&quot;
  select * from users where created_at &gt;= '&quot;, start_date , &quot;' and created_at &lt; '&quot;, end_date , &quot;' limit 10
  ;
  &quot;&quot;&quot;
  </code></pre>
  <p>With the error message: <strong>(psycopg2.errors.InvalidDatetimeFormat) invalid input syntax for type date: &quot;&quot;, start_date , &quot;&quot;</strong></p>
  <p>How can I change it? Thanks!</p>