Hi Angelo,

sorry, I missed the datetime in the title (duh!).

The date function belongs to the datetime object so it would be
available in the rows only, the field does not have it:

for row in rows:
  print row.data.date()

Note that the year month day hour minute second functions might not be
available in all DBs since the SQL implementation varies.

By the way, the MSSQL adapter has it wrong in 1.94.5, I have to check
on the newer versions.
Hmmm... that means I have never came across the need for those
functions.

If you are only working with SQLite then adding date() or time() would
not be hard and they seem like sensible options. Maybe even add them
to other adapters as well.

Is the row.data.date() option enough for you?.

Denes.


On Jul 12, 5:39 pm, Angelo Compagnucci <angelo.compagnu...@gmail.com>
wrote:
> Sorry for being pedantic!
>
> I made an empty application with only a table in the model defined as:
>
> db.define_table('test',Field('data','datetime'))
>
> and inserted some datetimes.
>
> then I made a method in the controller:
>
> def getdata():
>     rows = db(db.test).select()
>     return dict(rows=rows)
>
> and it works.
>
> It works also:
>
> def getdata():
>     rows = db(db.test).select(db.test.data.year())
>     return dict(rows=rows)
>
> but if I try:
>
> def getdata():
>     rows = db(db.test).select(db.test.data.date())
>     return dict(rows=rows)
>
> web2py throws an exception with the message:
>
> File "/home/angelo/DEV/web2py/applications/welcome/controllers/default.py",
> line 13, in getdata
>     rows = db(db.test.ALL).select(db.test.data.data())
> AttributeError: 'Field' object has no attribute 'date'
>
> So what's wrong?
>
> Thank you!
>
> 2011/7/12 pbreit <pbreitenb...@gmail.com>:
>
>
>
>
>
>
>
> > I believe datetime is a Python datetime.datetime object and gets validated
> > by IS_DATETIME().
> >http://docs.python.org/library/datetime.html#datetime.datetime
> >http://web2py.com/book/default/chapter/07?search=IS_DATETIME

Reply via email to