0

I am using python and mysql connector and am trying to get all eventids from the mySQL DB between two different datetime stamps.

The DB is

 eventid | date | homeodds | drawodds | awayodds 

This is the code:

def findarbs(startdate, enddate):
cnx = mysql.connector.connect(**dbconfig)
cur = cnx.cursor()
command = "SELECT DISTINCT eventid, date FROM moneyline 
               WHERE 'date' > ('%s') AND 'date' < ('%s') 
               ORDER BY date asc" % (startdate, enddate)
print command
cur.execute(command)
result = cur.fetchone()
print result
while result is not None:
    print result[1]
    result = cur.fetchone()

And the call to the method:

findarbs("2015-03-01 15:00:38", "2015-03-08 15:00:38")

Now if I change the command to:

command = "SELECT DISTINCT eventid, date FROM moneyline 
               WHERE 'date' > ('%s') 
               ORDER BY date asc" % (startdate)

it sucessfully selects the correct eventids and dates. If I change it to less than it also works. But when I try to combine them or use the BETWEEN command I get NONE back.

5
  • The code looks fine. Are you certain there are actual records in the DB that fall between that date range? Commented Mar 9, 2015 at 15:11
  • Yes I'm sure there are. That was what I was hoping, would be an easy fix. Commented Mar 9, 2015 at 15:15
  • The issue was having date in ' ' I removed the ' ' and it now works. I really should rename date column. Commented Mar 9, 2015 at 15:22
  • @Vuzuggu yes you should :) while you at it remember that it's all too easy to do the same in python - id, dir - some of the big offenders... Commented Mar 9, 2015 at 15:48
  • Or just use standard conform SQL syntax. Commented Mar 10, 2015 at 6:09

1 Answer 1

2

Wrong type of quotes:

'date'

-->

`date`

'date' is a string that evaluates as 0.

Also, not that neither :38 is captured by > and <.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.