title: Set a date variable to SQL query in Python
body: <p>I want to do sql query in python. I could use cx_oracle to connection database in python:</p>
  
  <pre><code># Build connection
  conn_str = u'username/password@host:1521/sid'
  conn = cx_Oracle.connect(conn_str)
  </code></pre>
  
  <p>Now I'm trying to retrieve data from the database by using SQL query in Python:</p>
  
  <pre><code>sql_select_statement = """SELECT * FROM TABLE 
  WHERE DATE BETWEEN '20-oct-2017' AND '30-oct-2017'"""
  </code></pre>
  
  <p>Assume we don't know the starting date, we only have a date variable called starting_time, and its value is a datetime %m/%d/%Y. Also, ending_time is yesterday, I would like to modify my SQL query as:</p>
  
  <pre><code>sql_select_statement = """SELECT * FROM TABLE 
  WHERE DATE BETWEEN '20-oct-2017' AND sysdate-1"""
  
  df = pd.read_sql(sql_select_statement, conn)
  </code></pre>
  
  <p>It works and generate a new df, but how to replace '20-oct-2017' with the variable starting_time? It's inside the sql query, and it's datetime format, so general python method like 'd%' % variable doesn't work. How to solve this problem? Thanks!</p>