Hi Denes,

thank you for your time!

row.data.date() could be the solution to the problem, but it forces me
to traverse the table returned by the query and build another table
with dates instead of datetimes... Not the best solution in speed and
elegance!

I think that a query like the one I made it's really common. I have a
timestamp and I want to count the occurences of a determined event by
date exctracted by the timestamp. I think that excrating the date (or
the time) from a datetime it's really a speedy operation if
accomplished by the database, and should be supported by all major
databases ( I think really all databases!).

By the way I resolved with this quick and dirty hack:

rows = db(db.test).select(db.test.data[:10])

slicing the first 10 character is enough for me!

If anyoune intrested, I'll explore te possibility to add a .date() and
a .time() to FIeld object, or find a way to concatenate .year()
.month() .day()!

Thank you!

2011/7/13 DenesL <denes1...@yahoo.ca>:
> 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