I'm stuck whith a really simple thing, but the simpler are the worst!
I wrote this query:
rows = dbradius(dbradius.radacct.CalledStationId==hsname).select(
count,
dbradius.radacct.AcctStartTime.year(),
dbradius.radacct.AcctStartTime.month(),
dbradius.radacct.AcctStartTime.day(),
groupby=entry_date)
Query works well, but I want a signle field for the date part, not the
three fields (year, month, day) I obtain.
There is a simple way to accomplish this?
Thank you!
What I'm trying to do is to select the date part from a datetime as
specified in the email subject, so the AcctStartTime field is a
datetime.
I'm navigating the epydoc documentation for dal.Field
http://www.web2py.com/examples/static/epydoc/web2py.gluon.dal.Field-class.html
and I cannot find reference for the date() method (only
year(),month(), day(), hour(), minutes(), seconds()) . Perhaps the
documentation is out of date.
I made several tries and in one of this I tryed also the date() method
in a query something like this:
rows = dbradius(dbradius.radacct.CalledStationId==hsname).select(
count,
dbradius.radacct.AcctStartTime.date(),
groupby=entry_date)
and it throws an exception. I can really make a mistake, so I'll try
your suggestion as soon as possible!
Thank you.
2011/7/12 DenesL <dene...@yahoo.ca>:
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 <pbreit...@gmail.com>:
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 <dene...@yahoo.ca>:
Well yes, I called it a dirty hack!
I'm looking for a function to extract date and time from a datetime db
side and I think I found one for every database supported by the DAL,
I'm in the process of review my research.
I'm intrugued in the process to add new date() and time() functions to
Filed class.
>>>> rr=db(db.test).select(db.test.data)
>>>> print rr[0]
> <Row {'data': datetime.datetime(2011, 7, 15, 14, 34, 18)}>
>
>>>> rr=db(db.test).select(db.test.data[:10])
>>>> print rr[0]
> <Row {'_extra': <Row {'SUBSTR(test.data,1,(11 - 1))': u'2011-07-15'}>}
Yes, I noticed that, a substring command returns a string, and not a
date object ... But for me it will suffice.
Thank you!