[Tutor] Dates

John CORRY john.corry at ntlworld.com
Sun Sep 10 13:02:16 CEST 2006


Alan,

Thanks for the help.  I have converted the dates to strings but I get
the same error.  Please see the updated code below, is this what you
meant by converting the dates to strings?

import mx.ODBC
import mx.ODBC.Windows
import mx.DateTime
import datetime
a = datetime.date(2006,01,31)
b = datetime.date(2006,12,31)
c = str(a)
d = str(b)
print a,b,c,d

db = mx.ODBC.Windows.DriverConnect('DSN=tnt')
c = db.cursor()
c.execute('SELECT * FROM times where rt_weekst >= ? and rt_weekst <= ?
and rt_type == ?', (c,d,"R",))    
for row in c.fetchall():
    print row
    row = str(row)
    
c.close()    


The output is below:

2006-01-31 2006-12-31 2006-01-31 2006-12-31
Traceback (most recent call last):
  File "C:\test\timemanager.py", line 18, in ?
    c.execute('SELECT * FROM times where rt_weekst >= ? and rt_weekst <=
?  and rt_type == ?', (c,d,"R",))
DataError: ('22005', 301, '[Microsoft][ODBC Visual FoxPro
Driver]Operator/operand type mismatch.', 4579)

Is there another way I can approach this problem?  Say if I use
something like:

c.execute('SELECT * FROM times where rt_weekst >= date(?) and rt_weekst
<= date(?)  and rt_type == ?', (c,d,"R",))

I get the following error:

2006-01-31 2006-12-31 2006-01-31 2006-12-31
Traceback (most recent call last):
  File "C:\test\timemanager.py", line 18, in ?
    c.execute('SELECT * FROM times where rt_weekst >= date(?) and
rt_weekst <= date(?)  and rt_type == ?', (c,d,"R",))
ProgrammingError: ('37000', 229, '[Microsoft][ODBC Visual FoxPro
Driver]Too few arguments.', 4579)

Thanks for any suggestions.

John.




More information about the Tutor mailing list