title: How to use time data to select records in SQLite
body: <p>I'm a beginner programmer, and I need to build a program that will allow me to retrieve records based on the time they were collected. I'm doing this using SQLite inside a python framework. </p>
  
  <p>My code is as follows: </p>
  
  <pre><code>cur.execute("CREATE TABLE Conc(Timesec INT, Timehrs REAL, Photon INT, hms TEXT);")
  
  creader = csv.reader(open(FileName, 'rb'), delimiter=',')
  t = (creader,)
  for t in creader:
      cur.execute("INSERT INTO Conc VALUES(?,?,?,?)", t)
  </code></pre>
  
  <p>This code works fine, and creates a table with the following data: </p>
  
  <pre><code>time(sec), time(h), photons, time (H:M:S) 
  0.0 , 0.0000 ,         0 , 11:16:36
  5.0 , 0.0014 ,      1698 , 11:16:41
  10.0 , 0.0028 ,      1793 , 11:16:46
  15.0 , 0.0042 ,      1764 , 11:16:51
  20.0 , 0.0056 ,      1751 , 11:16:56
  25.0 , 0.0069 ,      1779 , 11:17:01
  </code></pre>
  
  <p>Which goes on for several million entries (a new record every 5 sec.) </p>
  
  <p>I'm trying to come up with a way to use the H:M:S time to retrieve rows, calculate some averages, then apply the solution to other rows in the table. I've got a solution working that uses elapsed time in sec., but that makes it difficult to apply the code to other files (they don't all start at the same time). </p>
  
  <p>My goal is to call specific rows between 12:00:00 and 12:09:00, for instance. </p>
  
  <p>I've tried this: </p>
  
  <pre><code>query= cur.execute("SELECT AVG(Photon) FROM Conc WHERE hms BETWEEN strftime('%M', '12:00:11') AND strftime('%M', '12:09:11');")
  print query
  for row in cur.fetchall():
      print "The photons are", row[0]
  </code></pre>
  
  <p>This doesn't throw any errors, but it's returning "The photons are None", so I'm clearly not phrasing this correctly. Any troubleshooting or help crafting a more elegant solution would be greatly appreciated. </p>