Hi,

how can I select records of a table that got 2 date fields (one datetime and a simple date) wich difference is a fixed value?

I thought this solution:

import datetime
today=datetime.datetime.today()
yesterday = today.date() - datetime.timedelta(days=1)

db.define_table('mytab',
    ...
    Field('date1','datetime',default=today),
Field('date2','date',default=yesterday)
)

db(db.mytab.date1-db.mytab.date1 == datetime.timedelta(days=2).select()
but thats wat I got:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "<Path>/web2py/gluon/dal.py", line 4507, in select
    return self.db._adapter.select(self.query,fields,attributes)
  File "<Path>/web2py/gluon/dal.py", line 996, in select
    sql = self._select(query,fields,attributes)
  File "<Path>/web2py/gluon/dal.py", line 929, in _select
    sql_w = ' WHERE ' + self.expand(query)
  File "<Path>/web2py/gluon/dal.py", line 799, in expand
    return expression.op(expression.first, expression.second)
  File "<Path>/web2py/gluon/dal.py", line 721, in AND
    return '(%s AND %s)' % (self.expand(first),self.expand(second))
  File "<Path>/web2py/gluon/dal.py", line 799, in expand
    return expression.op(expression.first, expression.second)
  File "<Path>/web2py/gluon/dal.py", line 751, in EQ
return '(%s = %s)' % (self.expand(first),self.expand(second,first.type))
  File "<Path>/web2py/gluon/dal.py", line 805, in expand
    return self.represent(expression,field_type)
  File "<Path>/web2py/gluon/dal.py", line 1106, in represent
    return repr(float(obj))
TypeError: float() argument must be a string or a number

Thank you very much for any help.

    Manuele

Reply via email to