title: Python date range query
body: <p>I am amending an existing app that queries a database and returns information from the past 7 days. I have incorporated a calendar app so one can pick their own dates to query.</p>
  
  <p>The calendar is working great</p>
  
  <pre><code>import tkinter as Tkinter
  import tkinter.font as tkFont
  import tkinter.ttk as ttk
  import ttkcalendar
  import pandas as pd
  import numpy as np
  import tkSimpleDialog  
  from datetime import date
  
  class CalendarDialog(tkSimpleDialog.Dialog):
      """Dialog box that displays a calendar and returns the selected date"""
  
      def body(self, master):
          self.calendar = ttkcalendar.Calendar(master)
          self.calendar.pack()
  
      def apply(self):
          self.result1 = self.calendar.selection
          self.result2 = self.calendar.selection
  
  class CalendarFrame(Tkinter.LabelFrame):
  
      def __init__(self, parent):
          Tkinter.LabelFrame.__init__(self, parent, text="Choose Dates")
  
      def getbegindate():
          cd = CalendarDialog(self)
          self.result1 = cd.result1
          self.Begin_date.set(self.result1.strftime("%m/%d/%Y")) 
  
      def gettodate():
          cd = CalendarDialog(self)
          self.result2 = cd.result2
          self.To_date.set(self.result2.strftime("%m/%d/%Y"))
  
      self.Begin_date = Tkinter.StringVar()
      self.To_date = Tkinter.StringVar()
  
      def get_date():
          end = self.result2.strftime("%m/%d/%Y")
          start = self.result1.strftime("%m/%d/%Y")
          end1 = self.result2.strptime(end, "%m/%d/%Y").date()
          start1 = self.result1.strptime(start, "%m/%d/%Y").date() 
          delta = (end1 - start1).days
          daterange = [pd.date_range(start, end)]
          for single_date in daterange:
              x = single_date.strftime("%m/%d/%Y")
          rundate = x
          print(rundate) 
  
      Tkinter.Button(self, text="From date", command=getbegindate).grid(column=0, row=0)
      Tkinter.Entry(self, textvariable=self.Begin_date).grid(column=1, row=0)
      Tkinter.Entry(self, textvariable=self.To_date).grid(column=1, row=1)
      Tkinter.Button(self, text="To date", command=gettodate).grid(column=0, row=1)
      Tkinter.Button(self, text="SUBMIT", command=get_date).grid(column=0, columnspan=3)
  
  def main():
      root = Tkinter.Tk()
      root.wm_title("Pick1")
      root.geometry("250x150+100+100")
      CalendarFrame(root).grid()
      root.mainloop()
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>The weeklyrpt still works fine when going back 7 days.</p>
  
  <p>When a date range is chosen it returns "none" and returns an unpopulated screen. How do I get the dates from the calendar (Pick1.py) to populate my query</p>
  
  <pre><code>app_window = tk.Tk()
  app_window.withdraw()
  
  def rundate():
      result = tkinter.messagebox.askyesno(title="Rundate", message="back 7 days?")
      # result = tkinter.messagebox.askyesno()
      if result == True:
          rundate = date.today() - timedelta(7)
          return rundate
      else:
          os.system("pick1.py")
          def get_date():
                  end = self.result2.strftime("%m/%d/%Y")
                  start = self.result1.strftime("%m/%d/%Y")
                  daterange = [pd.date_range(start, end)]
                  for single_date in daterange:
                      x = single_date.strftime("%m/%d/%Y")
                  rundate = x
                  return rundate
  
  rundate = rundate()
  print(rundate)
  
  # Query permits made effective since rundate
  query = '''select `NPDES_ID`, `EffectiveDate`, `FacilityName`, `StateFacilityID`, `City`, `CountyName`
          from Permits 
          where `EffectiveDate` &gt;= ?
          order by `NPDES_ID`'''
  
  IDS=[]
  FacCodes=[]
  PermStrings=[]
  PayStrings=[]
  OwnerStrings=[]
  MTB=[]
  MTG=[]
  MTR=[]
  SWC=[]
  MT0=[]
  count=0
  # for each row in result of query
  for row in cur.execute(query, (rundate, )):
      try:
          d= row[1].strftime('%m/%d/%Y')
      except:
          d=""
      # create a display string with the appropriate information permit # - date -  facility name - city, county
      for i in range(len(row)):
              if not row[i]:
              row[i] = ""
  
      permitstring=row[0]+" | "+d+"\t | "+row[2]+"\t | "+row[4]+", "+row[5]+" County"
      IDS.append(row[0])
      tempid=row[0]
      # add the index to the appropriate permit type array, used to display seperately
      if tempid[0:3]=="MTB":
          MTB.append(count)
      if tempid[0:3]=="MTG":
          MTG.append(count)
      if tempid[0:4]=="MTR0":
          MTR.append(count)
      if tempid[0:3]=="MT0" or tempid[0:3]=="MT4" or tempid[0:3]=="MTX":
          MT0.append(count)
      if tempid[0:4]=="MTR1":
          SWC.append(count)
      FacCodes.append(row[3])
      PermStrings.append(permitstring)
      count+=1
  </code></pre>
  
  <p>This is a rather large app so I hope I am including the important parts to see where I am failing</p>