title: How to search between two dates in python using SQL
body: <p>im trying to retrieve data about a site between two dates and im receiving the error message <code>1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' date &gt;= '2021-05-04' AND date &lt;= '2021-05-07'' at line 1</code>. Im not sure whether its the SQL and I've tried using <code>BETWEEN date &gt;= %s AND date &lt;= %s</code></p>
  <p>Ive included the full section of code below</p>
  <pre class="lang-py prettyprint-override"><code>    def searchindividual():
          screen19 = Tk()
          screen19.geometry(&quot;300x250&quot;)
          screen19.title(&quot;Rooms&quot;)
          individualsiteID_info = sitename5_entry.get().strip()
          print(individualsiteID_info)
          date1 = date1_entry.get()
          print(date1)
          date2 = date2_entry.get()
          cursor = cnn.cursor()
          # combine the two SQL statements into one
          sql = &quot;SELECT siteID FROM Sites WHERE siteName = %s&quot;
          cursor.execute(sql, [individualsiteID_info])
          indivsiteID = cursor.fetchall()
          print(indivsiteID[0][0])
          sql2 = &quot;SELECT * FROM questions WHERE siteID4_fk = %s, date &gt;= %s AND date &lt;= %s&quot;
          cursor.execute(sql2, [indivsiteID[0][0], date1, date2])
          answers = cursor.fetchall()
          # remove previous result (assume screen13 contains only result)
          for w in screen19.winfo_children():
              w.destroy()
          if rooms:
              for i, row in enumerate(answers):
                  answeredquestions = row[0]
                  answeredquestionsvals = answeredquestions
                  btn = Button(screen19, text=answeredquestions)
                  btn.grid(row=i, column=0)
              else:
                  Label(screen19, text=&quot;No recorded answers found&quot;).grid()
          
  </code></pre>