title: Python expression to find all dates in a database field that are between two dates
body: <p>I have built a python script that first prints all of last week's dates and then two variables are created that are the first and last dates so that I can then write an expression to find all of the dates in a field that are between those dates. Here is what I have so far:</p>
  
  <pre><code>import arcpy, sys, string, os, time, shutil, tempfile, logging, datetime
  # this is the current date
  now = datetime.datetime.now()
  
  # subtract 7 days from the current date
  SevenDaysBack = now - datetime.timedelta(days=7)
  
  # this is the date of the first day of last week
  now_day_1 = SevenDaysBack - datetime.timedelta(days=now.weekday())
  
  dates = {}
  #this lists out all the dates of last week
  for n_week in range(1):
      dates[n_week] = [(now_day_1 + datetime.timedelta(days=d+n_week*7)).strftime("%Y%m%d") for d in range(7)]
  ##for d in range(7):
      ##dates = [(now_day_1 + datetime.timedelta(days=d*7)).strftime("%Y%m%d")]
  print dates
  
  From_Date = dates[n_week][0]
  To_Date = dates[n_week][6]
  print From_Date
  print To_Date
  
  SaleDateExpression = [DATE_SOLD] "between" + From_Date + "and" + To_Date
  print SaleDateExpression
  </code></pre>
  
  <p>The script works up until I try to create the Expression that will be used in a later function. I'm sure its a syntax issue but I don't know how to make it work.</p>